【发布时间】:2011-07-06 11:37:13
【问题描述】:
我有一个包含 UITextView、UILabel 和 UIButton 的自定义单元格的表格视图。
问题是,
第一次加载表格时,会显示 2 个单元格并且没问题。但是在滚动表格时,任何单元格都会滚动出屏幕,应用程序突然终止,而没有向控制台显示任何异常错误。
这是我的代码,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"In tableView:Cell");
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
CourtsFavoriteCustomCell* cell = (CourtsFavoriteCustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if( cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CourtsFavoriteCustomCell"
owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CourtsFavoriteCustomCell class]])
cell = (CourtsFavoriteCustomCell *)oneObject;
//*********** Creating button inside each TableView cell..
UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[mapButton setFrame:CGRectMake(120.0f, 157.0f, 72.0f, 32.0f)] ;
//btnDetail.backgroundColor = [UIColor grayColor];
[mapButton setTitle:@"Map" forState:UIControlStateNormal];
[mapButton setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
//[mapButton.titleLabel setFont:[UIFont fontWithName:@"Verdana-Bold" size:12]];
[mapButton setBackgroundColor:[UIColor clearColor]];
[mapButton sizeThatFits:mapButton.frame.size];
[cell addSubview:mapButton];
[mapButton addTarget:self
action:@selector(cellMapButtontapped:)
forControlEvents:UIControlEventTouchUpInside];
forState:UIControlStateNormal];
}
NSLog(@"App get terminated after showing this log message to console when scrolling tableview");
cell.name.text = favCourtName; // name is a UIText view and if comment this line of code, every thing works fine
cell.address.text = favCourtAddress;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
我在我的自定义单元格中使用 UITextView(代码中的 Cell.name)。当我尝试将 UITextView 代码注释掉时,一切正常。
请帮帮我 :)thanx..
【问题讨论】:
-
什么是
favCourtName?是否设置正确? -
我可以知道 uitextview 对象在哪里声明了相同的类或在哪里。属性很重要,所以如果将更改分配给保留
-
@deepak ,favCourtName 是一个 NSString,是的,它已正确设置..
-
@maheswaran , UItextView 在自定义单元格中声明。 @property (nonatomic, retain) UITextView * name;
标签: iphone objective-c uitableview uitextview