我正在cellForRowAtIndexPath,我試圖嵌入到單元格的文本。現在,嵌入部分一切都很好,但當我嘗試加載除第一行之外的所有文本視圖時,我遇到了最奇怪的問題。iphone sdk - 與TableView單元格的奇怪錯誤
注意:我希望TextView除了表格中的第一行外。
問題是,當我執行if語句檢查indexpath.row,然後向下滾動文本視圖時,在某些單元格中不可見。它與我有着相當大的高度> 200的細胞有關,它們最初在屏幕外。當我向下滾動時,就像下面最下面一個可見單元格下面的單元格現在正在響應== 0的索引路徑行。
我完全困惑,有沒有人有任何想法?
我的代碼
// 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
CGRect frame; frame.origin.x = 5; frame.origin.y = 10; frame.size.width = 20; frame.size.height = 25;
// ..some unrelated setup in here
//textbox setup
textView = [[UITextView alloc] initWithFrame:CGRectMake(30, 80, 500, 150)];
textView.layer.cornerRadius = 10;
textView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.2];
textView.font = [UIFont fontWithName:@"Helvetica" size:17];
textView.text = @"test-content";
textView.layer.borderWidth = 1;
textView.layer.borderColor = [[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.9] CGColor];
textView.tag = 4;
if (indexPath.row != 0) {
[cell.contentView addSubview:textView];
[textView release];
}
}
// a little more unrelated stuff
return cell;
}
有人能看出問題?
感謝
我很難想象您的描述。你能附上截圖嗎? – Giao 2010-02-21 23:42:03