单击按钮时将NSMutable数组传递给UITableview [英] NSMutable array to UITableview when button clicked
问题描述
当我单击收件箱按钮时,我想在UITableView中显示我的电子邮件标题,我的电子邮件标题存储在NSMutable数组中,
i want to show my email headers in a UITableView when inbox button clicked, my email headers is stored in an NSMutable Array,
-(IBAction)buttonInbox:(id)sender{
NSLog(@"Inbox Button Clicked %@",buttonInbox);
[self select:@"INBOX"];
NSArray *lines = [self sendCommand:@"fetch 1:* (body[header.fields (from subject date)])"];
//NSMutableArray *emaiArray= [[NSMutableArray alloc] init];
NSMutableString *totalEmail= [NSMutableString stringWithString:@""];
int counter = 0;
int i =0;
NSRange tmp;
for(i=0;i<[lines count];i++)
{
NSString *line = [lines objectAtIndex:i];
//NSLog(@" Burda %@" ,line);
tmp = [line rangeOfString:@"Date:"];
if( tmp.location != NSNotFound )
{
//NSLog(@" Date basildi %@" ,line);
counter++;
[totalEmail appendString:line ];
}
tmp = [line rangeOfString:@"From:"];
if (tmp.location != NSNotFound ) {
//NSLog(@" From basildi %@" ,line);
counter++;
[totalEmail appendString:line ];
}
tmp = [line rangeOfString:@"Subject:"];
if (tmp.location != NSNotFound ) {
//NSLog(@" Subject basildi %@" ,line);
counter++;
[totalEmail appendString:line ];
}
if (counter==3) {
[emailList addObject:totalEmail];
counter =0;
NSLog(@"total Email %@" ,totalEmail);
totalEmail = [NSMutableString stringWithString:@""];
}
}
}
到目前为止,我已经尝试过此操作,但在单击按钮的事件时找不到任何可放置此内容的准则,无论如何它仍然显示空的表格视图
i have tried this so far but couldnt find any guidelines to put this when button clicked events, this doesnt work any way it shows an empty tableview anyways
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [emailList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]] autorelease];
}
cell.textLabel.text = [emailList objectAtIndex: indexPath.row];
return cell;
}
推荐答案
尝试在buttonInbox:
选择器的末尾调用[[self tableView] reloadData]
.
Try calling [[self tableView] reloadData]
at the end of the buttonInbox:
selector.
这将刷新tableView.
This will refresh the tableView.
但是,我建议您查看UITableView的文档,并查看如何使用-(void) beginUpdates
和-(void) endUpdates
,以便您可以获得更好的视觉体验,并使表视图为进入的行设置动画.
I would, however, suggest looking at the documentation for UITableView and see how to use -(void) beginUpdates
and -(void) endUpdates
so you can get a better visual experience and let the table view animate the rows coming in.
这篇关于单击按钮时将NSMutable数组传递给UITableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!