2010-05-17 45 views
1

似乎無法擺脫警告。該警告是: '的UIImage' 可不迴應 '-scaleToSize'xcode可能不會響應警告

的@implmentation MyViewController上面我有這樣的@implementation:

@implementation UIImage (scale) 

-(UIImage*)scaleToSize:(CGSize)size 

{ 
UIGraphicsBeginImageContext(size); 
[self drawInRect:CGRectMake(0, 0, size.width, size.height)]; 
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return scaledImage; 
} 

@end 

然後,我有MyViewController實施

@implementation TodayNewsTableViewController 

@synthesize dataList; 

...... 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 

    static NSString *MainNewsCellIdentifier = @"MainNewsCellIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: MainNewsCellIdentifier]; 

    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier: MainNewsCellIdentifier] autorelease]; 

    } 

    NSUInteger row = [indexPath row]; 

NSDictionary *stream = (NSDictionary *) [dataList objectAtIndex:row]; 

NSString *title = [stream valueForKey:@"title"]; 

if(! [title isKindOfClass:[NSString class]]) 

{ 

cell.textLabel.text = @""; 

} 

else 

{ 

cell.textLabel.text = title; 

} 

cell.textLabel.numberOfLines = 2; 
cell.textLabel.font =[UIFont systemFontOfSize:10]; 
cell.detailTextLabel.numberOfLines = 1; 
cell.detailTextLabel.font= [UIFont systemFontOfSize:8]; 
cell.detailTextLabel.text = [stream valueForKey:@"created"]; 

NSString *i = [NSString stringWithFormat:@"http://www.mywebsite.co.uk/images/%@", [stream valueForKey:@"image"]]; 


NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:i]]; 

UIImage *newsImage = [[UIImage alloc] initWithData:imageURL] ; 


UIImage *scaledImage = [newsImage scaleToSize:CGSizeMake(50.0f, 50.0f)]; // warning is appearing here. 

cell.imageView.image = scaledImage; 

[imageURL release]; 

[newsImage release]; 

    return cell; 
} 

感謝您的時間提前。

框架

回答

2

要避免此警告,編譯器必須「看到」您的自定義方法聲明。所以,你應該把

@interface UIImage (scale) 

-(UIImage*)scaleToSize:(CGSize)size 

@end 

地方 - 或者相應的頭文件,或者在相同的實現文件,如果你不希望這種方法是當前文件外部訪問。

相關問題