1
我正在嘗試創建一個讀取json提要的iphone應用程序,並且在更新TableView時遇到了一些麻煩。無法重新加載UITableView
這是我TableViewController頭文件:
@interface LiveNewsController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
NSMutableData *responseData;
NSMutableArray *articleArray;
UITableView *tblView;
}
-(void) refreshPressed: (id)sender;
@property (nonatomic, retain) IBOutlet UITableView *tblView;
@end
這些都是一些部分我TableViewController實現文件:
@implementation LiveNewsController
@synthesize tblView;
-(id) init {
if(self = [super init])
{
self.title = @"Live News";
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"I am here %d",[articleArray count]);
return [articleArray count];
}
// 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 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"cellForRowAtIndexPath called. Data size %d", [articleArray count]);
NSUInteger row = [indexPath row];
cell.textLabel.text = [articleArray objectAtIndex:row];
return cell;
}
-(void) refreshPressed: (id)sender
{
NSLog(@"Reload Pressed. Data size: %d", [articleArray count]);
[tblView reloadData];
}
這是與我的.xib文件的截圖連接:
所以其主要思想是:
- 取articleArray
- 刷新時按下更新視圖(數據被正確地獲取,但片段在這裏不顯示它)
numberOfRowsInSection和CellForRowAtIndexPath只在視圖加載時調用一次,但按下reload按鈕時不會發生任何事情。
我查了tblView,它是無。我做了一些研究,並且讀到這通常是由.xib文件中的一些錯誤連接引起的,但我有三重檢查,並且我似乎無法找出問題所在。
任何幫助表示讚賞,
謝謝!
我試圖刪除tblView,沒有任何改變。該應用程序仍然工作,但它最初的問題仍然存在。數據未更新。 – Pepe 2011-03-15 23:17:37
它工作!雖然你的網絡連接有一個小延遲,但是你確實是對的。謝謝 ! – Pepe 2011-03-15 23:19:21