我想在点击收件箱按钮时在UITableView中显示我的电子邮件标题,我的电子邮件标题存储在NSMutable数组中,
-(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:@""];
}
}
}
到目前为止我已经尝试了这个但是当按钮点击事件时无法找到任何指导,这无论如何都无法显示空的tableview
- (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;
}
答案 0 :(得分:2)
尝试在[[self tableView] reloadData]
选择器的末尾调用buttonInbox:
。
这将刷新tableView。
但是,我建议查看UITableView的文档,看看如何使用-(void) beginUpdates
和-(void) endUpdates
,这样您就可以获得更好的视觉体验,并让表格视图为进入的行设置动画。