我有一个大问题。
[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;
}
更新:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dict count];
}
请帮帮我...