我遇到了一個很大的問題。重新加載數據(UITableView)不起作用
[self.tableView reloadData];
不工作,我不明白爲什麼。
[[self tableView] reloadData];
不工作過。
這裏是我的代碼:
.H
@interface ArticleViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
{
}
@end
.M
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
btnLeft = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btnLeft"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(loadPlist)];
self.navigationItem.leftBarButtonItem = btnLeft;
在loadPlist
方法,我正在寫一個文件的.plist。這部分工作正常。
一旦所有在的.plist文件中寫:
btnRight = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btnRight"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(reloadTheTB)];
self.navigationItem.rightBarButtonItem = btnRight;
- (void)reloadTheTB {
NSLog(@"Test reloadTheTB");
[[self tableView] reloadData];
}
如果我觸摸btnRight
,我可以在日誌 「Test reloadTheTB
」 中看到的。
這裏是tableView:cellForRowAtIndexPath:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
contentDictio = [dict objectAtIndex:indexPath.row];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
lblTemp1.text = [contentDictio objectForKey:@"title"];
if(indexPath.row % 2) {
UIView* myBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
myBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_grise"]];
cell.backgroundView = myBackgroundView;
}
else {
UIView* myBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
myBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_blanche"]];
cell.backgroundView = myBackgroundView;
}
}
return cell;
}
UPDATE:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dict count];
}
請幫助我......
,你必須創建實現代碼如下???? – Venkat
那麼你正在做什麼變化,而不是''tableView reloadData''反映' – mayuur
這是一個'UITableViewController'所以,我不需要創建tableView – user1269586