xcode может не отвечать на предупреждение - PullRequest
1 голос
/ 17 мая 2010

Не могу избавиться от предупреждения. Предупреждение: «UIImage» может не отвечать на «-scaleToSize»

над @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;
}

Спасибо за ваше время заранее.

Рама

1 Ответ

2 голосов
/ 17 мая 2010

Чтобы избежать этого предупреждения, компилятор должен «увидеть» объявление вашего пользовательского метода. Так что вы должны поставить

@interface  UIImage (scale)

-(UIImage*)scaleToSize:(CGSize)size

@end

где-нибудь - либо в соответствующий заголовочный файл, либо в тот же файл реализации, если вы не хотите, чтобы этот метод был доступен за пределами текущего файла.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...