Tôi khá mới phát triển Iphone. vì vậy hãy chịu tôi nếu tôi hỏi một số câu hỏi rất đơn giản.UITableView cellforrowatindexpath không được gọi là
Trong ứng dụng của tôi, tôi có nhiều chế độ xem (nghĩa là các tệp .xib). Khi nhấp vào nút trên giao diện chính (CouponWebsiteViewController.Xib) ứng dụng sẽ tải chế độ xem thứ hai (BrowseList.Xib) chứa một UITable và tôi phải điền UITable đó với một số dữ liệu. Tôi đã viết mã sau đây để điền vào dữ liệu trong hồ sơ BrowseList.m:
- (void) viewDidLoad{
arrayData = [[NSArray alloc] init];
arrayData = [arrayData arrayByAddingObject:@"dfsgdf"];
arrayData = [arrayData arrayByAddingObject:@"aaaaaa"];
self.lblNewScreen.text = [arrayData objectAtIndex:0];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrayData 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];
}
NSString *cellValue = [arrayData objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
[tableView setEditing:YES animated:YES];
return cell;
}
Nhưng Nó không được đưa dữ liệu trong bảng, khi tôi gỡ lỗi mã này tôi thấy rằng nó không được thực hiện phương pháp cellForRowAtIndexPath nhưng nó được gỡ rối numberOfRowsInSection và numberOfSectionsInTableXem các phương thức.
Nhưng điều thú vị là khi tôi viết cùng một mã trên CouponWebsiteViewController.m (tức là trên màn hình chính) thì nó đang điền dữ liệu vào bảng.
Vấn đề là mã này hoạt động tốt trên chế độ xem chính nhưng mã này không hoạt động cho các chế độ xem khác.
Bất kỳ ai có thể cho tôi biết tôi đang thiếu hoặc cách nào khác để điền UITable trên các chế độ xem khác với chế độ xem chính.
Cảm ơn trước. Gaurav
Thêm ** [self.tableView reloadData] ** vào trình phân tích cú pháp ** - (void)DidEndDocument: (NSXMLParser *) ** làm việc tốt cho tôi khi tôi gặp vấn đề tương tự. Cần nhớ NSXMLParser là một hoạt động SAX. – subv3rsion