2012-05-26 29 views
0

嗨,大家好,我無法將圖像文件製作爲我製作的自定義uitableview單元格。圖像太小,我不知道如何放大。 Thnx提前尋求幫助。無法獲取UIImage以適應自定義UITableViewCell

#import <UIKit/UIKit.h> 

@interface customCell : UITableViewCell 
{ 
    //UILabel *frontLabel;  
} 
@property(nonatomic , strong) IBOutlet UILabel *label; 
@property(nonatomic , strong) IBOutlet UILabel *label2; 
@property(nonatomic , strong) IBOutlet UIImageView *imgView; 
@end 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"cell"; 

    customCell * cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
    cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 


    User * user = [self.list objectAtIndex: indexPath.row]; 

    cell.label.text = user.username; 
    NSString *url = user.profilePic; 
    UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]; 
    cell.imageView.contentMode =UIViewContentModeScaleAspectFit; 
    cell.imageView.image =image; 

    return cell; 
} 

回答

1

在你customCell類(順便說一句的所有類應以大寫字母開頭,屬性和變量應該是小寫),你只需要你的imageView對象的frame屬性設置爲你想要的正確的大小和位置。

類似imageView.frame = CGRectMake(10., 10., 50., 50.)其中前兩個參數是圖像視圖右上角的x和y位置,後兩個參數是寬度和高度。

或者,由於您已將這些屬性指定爲IBOutlet,因此如果您使用XIB文件進行佈局,則應該已經在其中設置了大小設置。

沒有看到XIB的Interface Builder截圖或customCell的實現代碼,這是我能提供的最好的幫助。

+0

thnx,但我無法訪問imageView形式我的自定義類是奇怪的。我設置屬性和合成它,但是當我試圖self.imageView它不認爲它是關鍵詞 –

+0

那麼'UITableViewCell'已經有一個'imageView'屬性,所以你應該一定能夠訪問它,但它看起來像你的'UIImageView'是'imgView'。您可以不使用內置的'imageView'並使用您的'imgView'來代替。 –

+0

但是在你的UITableViewController中,當你在做'cell.imageView'時,通過'cell.imgView'來訪問你要添加到自定義單元格中的那個。 –

相關問題