我正在製作一個新的應用程序,它有四組非常相似的數據。我想使四個UIButtons與四個UITableViews導航到一個UITabBar。我不想製作四個按鈕來推送四組桌面視圖。我想用13個UIViews製作一個應用會使它比需要的更大。所以,我必須弄清楚如何讓UIButton動作改變表中的數據。我正在積極開展這個項目。任何的意見都將會有幫助。謝謝。如何使用UIButton Action來更改用於填充UITableView的NSArray?
0
A
回答
1
爲了更改表視圖數據源,您需要更改您的表代表上的numberOfRowsInSection返回的內容。我這樣做的一個方法是使用一個枚舉來表示我要使用,並有一個局部變量來保存這一個選擇
typedef enum
{
DataSetOne,
DataSetTwo
} DataSetEnum
@property(nonatomic, retain) DataSetEnum dataset;
@property(nonatomic, retain) NSArray *datasetone;
@property(nonatomic, retain) NSArray *datasettwo;
- (void) viewDidLoad
{
dataset = DataSetOne;
}
- (IBAction) buttonPressed
{
dataset = DataSetTwo;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(dataset == DataSetOne)
{
return [self.datasetone count];
}
else if(dataset == DataSetTwo)
{
return [self.datasettwo count];
}
}
該數據集,然後在的cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(dataset == DataSetOne)
{
//configure cell
}
}
0
NSArray* data = ...
然後在您的按鈕的方法:如果你的數據是相似的,你可以只從每個按鈕的IBAction
變量設置一個數據
-(IBAction*)clickedButton1:(id)sender {
data = [self getButton1Data]
[self reloadAll]
}
+0
謝謝,這聽起來像個好主意。我會嘗試。 – 2011-03-31 18:01:33
+0
我決定不這樣做,所以不會有任何答案。 – 2011-08-26 04:14:52
相關問題
- 1. 如何從NSArray填充UITableView?
- 2. 如何用XML填充UITableView?
- 3. 使用UIButton填充UITableCellView
- 4. 如何從使用JSONKit創建的NSDictionary正確地填充UITableView NSArray?
- 5. 使用數組填充UITableView
- 6. 使用數組填充UITableView
- 7. 使用NSArray的填充的CollectionView
- 8. 如何填充UITableView?
- 9. 奇怪填充用的UIButton
- 10. 用dataTaskWithRequest填充uitableview
- 11. 用CFArray填充UITableView?
- 12. 用NSArray和NSMutableArray填充NSStackView
- 13. NSArray更改後UITableView沒有更新
- 14. 用變量填充UITableView
- 15. 用日曆天填充UITableView
- 16. 使用angularjs更改基於頁眉高度的頂部填充
- 17. 如何使用NSDictionary從NSArray中填充數據?
- 18. 使用UIButton清除UITableView中的所有UITextField更改
- 19. 使用來自NSMutableArray的數據填充UITableView
- 20. 使用解析和url填充UItableview
- 21. 使用jQuery可調整大小來更改填充
- 22. 如何使用UITableView來更改UITextView的內容
- 23. 使用NSArray加載UITableView
- 24. 使用Linq來填充類
- 25. 使用jQuery來填充ValidatorHookupControl
- 26. 在Swift中以編程方式更改UIButton的文本(填充)
- 27. 如何使用ActionScript 2更改填充顏色?
- 28. 如果UISearchBar已填充,請更改UITableView setBackgroundColor
- 29. 用JS更改svg的CSS填充
- 30. 如何使用解析元素填充UITableView?
謝謝。我一定會嘗試你的方法。 – 2011-03-31 17:52:35