2012-04-12 53 views
0

我有一个代码中的对象布局问题。 这里是当前和期望状态的画面:在UITableviewcell布局UIImage

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 2012-04-12 07:58:07

+0

嗯...似乎你只问你的一部分需求。如果你能更新你的问题,包括你打算实现的目标,那将是非常棒的。但我不认为你会有问题添加一个事件到uiImage。我会检查是否当我把我的手放在Mac上。 – lancegoh 2012-04-13 09:46:17

相关问题