我通過爲主tableview創建自定義單元格,在tableview的每個單元格中都有一個tableview。問題是我可以看到除第一個之外的所有索引路徑的tableview內容。如果我滾動tableview使第一個單元格出來,並滾動第一個單元格,第一個單元格中的內容顯示。在indexpath零的項目不會顯示,直到indexpath 0滾出屏幕
請找我的代碼如下
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [itemArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *[email protected]"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
for (int i=0; i<[itemArray count]; i++) {
////NSLog(@"row is %d",i);
if (indexPath.row==i) {
cell.textLabel.text=[itemArray objectAtIndex:i];
}
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
誰能告訴我,爲什麼它正在發生。我想要在屏幕上看到第一個單元格的內容。
這幾乎是不可能回答'UITableView'沒有看到你的'的tableView的問題:的cellForRowAtIndexPath:'方法。 – dasblinkenlight
和numberOfRowsInSection – Radu
@dasblinkenlight請檢查我的代碼 – surendher