Vote count:
0
I am stuck right now with how to create my UITableView. Right now it works fine with 1 object providing the data for it's rows and cells. The problem is, I have a 2nd object that I also want to use in the table view. Normally, this is very easy and I just create 2 sections in the UITableView and use one object for the first section, and use the second object for the second section.
But for this UITableView, I only want to use 1 section. And I need to programatically populate the row's and cell's with text from BOTH of the objects. I have no idea how to do this though when only using 1 section.
Here are all of my method implementations that help create my UITableView:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1 ;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.messages count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"Inbox Messages";
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"SettingsCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
PFObject *message = [self.messages objectAtIndex:indexPath.row];
UIImage *selectMessageButtonImage = [UIImage imageNamed:@"SliderThumb-Normal-G"];
UIImage *selectMessageButtonImageHighlighted = [UIImage imageNamed:@"SliderThumb-Normal"];
UIButton *openMessageButton = [[UIButton alloc]init];
openMessageButton.frame = CGRectMake(237, -10, 64, 64);
[openMessageButton setImage:selectMessageButtonImage forState:UIControlStateNormal];
[openMessageButton setImage:selectMessageButtonImageHighlighted forState:UIControlStateHighlighted];
[openMessageButton setImage:selectMessageButtonImageHighlighted forState:UIControlStateSelected];
[openMessageButton addTarget:self action:@selector(handleTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
openMessageButton.tag = indexPath.row;
[cell.textLabel setText:[message objectForKey:@"senderName"]];
NSString *fileType = [message objectForKey:@"fileType"];
if([fileType isEqualToString:@"image"]) {
cell.imageView.image = [UIImage imageNamed:@"icon_image"];
} else {
//no image
}
[cell.detailTextLabel setText:@""];
[cell.contentView addSubview:openMessageButton];
return cell;
}
The object that I am currently using with this UITableView is called message
. I want to create a 2nd object called message2
and place it's data in the UITableView as well.
I realize that for the numberOfRowsInSection
method implementation I could just return the added count's of both objects, but I don't know how to work the 2nd object into the rest of the code.
Aucun commentaire:
Enregistrer un commentaire