#iphone #objective-c #uitableview #nsmutablearray
#iPhone #objective-c #uitableview #nsmutablearray
Вопрос:
я хочу показывать заголовки моей электронной почты в 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;
}
Ответ №1:
Попробуйте вызвать [[self tableView] reloadData]
в конце buttonInbox:
селектора.
Это обновит TableView.
Я бы, однако, посоветовал взглянуть на документацию по UITableView и посмотреть, как использовать -(void) beginUpdates
и -(void) endUpdates
, чтобы вы могли улучшить визуальное восприятие и позволить табличному представлению анимировать входящие строки.
Комментарии:
1.это не сработало, потому что мой табличный вид объявлен как UITableView * MyTableView; @property (неатомный, сохранить) IBOutlet UITableView * MyTableView; и я не использую какой-либо метод mytableview в моем файле .m?
2. я понимаю это, я забыл перетащить делегат в filesowner для tableview