NSString *myMessage=messageField.text;
[messageArray addObject:myMessage]];
messageContentArray=[[NSMutableArray alloc] initWithArray:messageArray];
[_tableView reloadData];
UITableviewがあり、データソースとして文字列のNSMutable配列を使用したところ、正常に機能します。しかし今、私は上記のようにボタンをクリックしてこの配列に別の文字列を追加したいのですが、ボタンに触れるとすぐにアプリケーションがクラッシュして
'NSInvalidArgumentException'、理由:'-[NSCFString count]:認識されないセレクターがインスタンス0x4e11cf0に送信されました'
これを行う方法私のテーブルビューは次のとおりです私を助けてください
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [messageContentArray count];
}
#pragma mark -
#pragma mark UITableView Delegaates
static CGFloat padding = 20.0;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"messagesCellIdentifier";
SMMessageViewTableCell *cell = (SMMessageViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[SMMessageViewTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *usrid=[useridArray objectAtIndex:indexPath.row];
NSData *imgData1 = (NSData*)[[NSUserDefaults standardUserDefaults] objectForKey:@"lisnerImage"];
UIImage *img1 = [UIImage imageWithData: imgData1];
// CGRect imageFrame=CGRectMake(5,20,25,30);
//CGRect imageFrame1=CGRectMake(250,20,25,30);
//self.cellimage=[[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
// self.cellimage1=[[[UIImageView alloc] initWithFrame:imageFrame1] autorelease];
if ([usrid caseInsensitiveCompare:friend_Id] == NSOrderedSame) {
[cell.usrImage setFrame:CGRectMake(250,
20,
25,
30)];
cell.usrImage.image = userImage.image;
// self.cellimage1.image=userImage.image;
// [cell.contentView addSubview:self.cellimage1];
NSString *messages1 = [messageContentArray objectAtIndex:indexPath.row];
CGSize textSize = { 260.0, 10000.0 };
CGSize size = [messages1 sizeWithFont:[UIFont systemFontOfSize:13]
constrainedToSize:textSize
lineBreakMode:UILineBreakModeWordWrap];
size.width += (padding/2);
cell.messageContentView.text = messages1;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.userInteractionEnabled = NO;
UIImage *bgImage = nil;
bgImage = [[UIImage imageNamed:@"aqua.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
[cell.messageContentView setFrame:CGRectMake(45 ,
20,
190,
size.height)];
[cell.bgImageView setFrame:CGRectMake(45,
17,
190,
size.height+padding)];
cell.bgImageView.image = bgImage;
}else {
//self.cellimage.image=img1;
// [cell.contentView addSubview:self.cellimage];
[cell.usrImage setFrame:CGRectMake(5,
20,
25,
30)];
cell.usrImage.image = img1;
NSString *messages1 = [messageContentArray objectAtIndex:indexPath.row];
CGSize textSize = { 260.0, 10000.0 };
CGSize size = [messages1 sizeWithFont:[UIFont systemFontOfSize:13]
constrainedToSize:textSize
lineBreakMode:UILineBreakModeWordWrap];
size.width += (padding/2);
cell.messageContentView.text = messages1;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.userInteractionEnabled = NO;
UIImage *bgImage = nil;
bgImage = [[UIImage imageNamed:@"orange.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
[cell.messageContentView setFrame:CGRectMake(45, 20, 190, size.height)];
[cell.bgImageView setFrame:CGRectMake( 45,
17,
190,
size.height+padding)];
cell.bgImageView.image = bgImage;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// return 65;
NSString *text = [messageContentArray objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height+20, 44.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}