2012-04-12 4 views
0

У меня проблема с компоновкой объектов в коде. Вот картина текущего и желаемого состояния:UIImage в макете UITableviewcell

enter image description here

А вот код

- (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; 
} 

ответ

0

на iOS5, используя прототип ячейки на IB будет самый простой выход для тебя.

Если вы не на ios 5, я настоятельно рекомендую использовать пользовательскую таблицу tableviewcell.

Краткое решение проблемы можно найти здесь по ссылке ниже.

UITableViewCell with image on the right?

+0

я сделал с UIImageView, но их я не мог поймать его ontouch события. вы можете увидеть здесь мой последний вопрос: http://stackoverflow.com/questions/10029049/catch-uiimageviewe-touch-in-uitableviewcell – Nir

+0

hmmm ... Похоже, вы задаете только часть своих требований. будет здорово, если вы сможете обновить свою проблему, включая то, что вы намереваетесь достичь. Но я не думаю, что у вас возникнет проблема с добавлением события в uiImage. Я проверю, если я получаю свои руки на mac. – lancegoh

Смежные вопросы