2012-04-12 9 views
0

私はコード内のオブジェクトのレイアウトに問題があります。ここで は現在、目的の状態の写真です:UITableviewセルレイアウトのUIImage

enter image description here

そしてここでは、iOS5を上のコード

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

で、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