2012-04-12 8 views
0

Ich habe ein Problem Layout die Objekte im Code. Hier ist ein Bild der aktuellen und gewünschten Status:UIImage in UITableviewcell Layout

enter image description here

Und hier ist der Code

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
if (self) { 
    self.title = NSLocalizedString(@"My Favorites", @"My Favorites"); 
    self.tabBarItem.image = [UIImage imageNamed:@"second"]; 

}  

favoritesTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 364) style:UITableViewStylePlain]; 
[favoritesTable setHidden:NO]; 
[favoritesTable setDelegate:self]; 
[favoritesTable setDataSource:self]; 

[self.view addSubview:favoritesTable];   

[favoritesTable release]; 

return self; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *cellIdentifier = @"<#MyCell#>"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
} 

NSInteger objectLocation = indexPath.row; 

FoodData* food = (FoodData*)[resultsArray objectAtIndex:objectLocation];  

cell.imageView.image = [UIImage imageNamed:@"paris.jpg"]; 
cell.imageView.frame = CGRectMake(270, 4, 40, 36);  

cell.imageView.userInteractionEnabled = YES; 
cell.imageView.tag = indexPath.row; 

UILabel* lblText = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 260, 20)]; 
UILabel* lblType = [[UILabel alloc] initWithFrame:CGRectMake(0, 21, 260, 20)]; 

[lblText setFont:[UIFont fontWithName:@"Helvetica" size:10.0]]; 
[lblType setFont:[UIFont fontWithName:@"Helvetica" size:9.0]]; 

lblType.textColor = [UIColor blueColor ]; 

[lblText setText:[food foodName]]; 
[lblType setText:[food foodType]]; 

[cell addSubview:lblText]; 
[cell addSubview:lblType]; 

[lblText release]; 
[lblType release]; 

return cell; 
} 

Antwort

0

auf ios5, die Nutzung der Prototyp Zelle auf der IB wird der einfachste Weg sein für dich.

Wenn Sie nicht auf iOS 5 sind, empfehle ich sehr, eine benutzerdefinierte Tableviewcell zu verwenden.

Die kurze Lösung für Ihr Problem finden Sie hier im folgenden Link.

UITableViewCell with image on the right?

+0

ich mit UIImageView tat, aber sie kann ich nicht sein OnTouch Ereignis fangen. Sie können hier meine letzte Frage sehen: http://stackoverflow.com/questions/10029049/catch-uiimageviewe-touch-in-guidablecell – Nir

+0

hmmm ... Scheint so, als ob Sie nur einen Teil Ihrer Anforderungen stellen. Es wäre großartig, wenn Sie Ihr Problem aktualisieren könnten, einschließlich was Sie erreichen wollen. Aber ich denke nicht, dass Sie Probleme haben werden, dem uiImage ein Ereignis hinzuzufügen. Ich werde es überprüfen, wenn ich einen Mac bekomme. – lancegoh

Verwandte Themen