iPhone sdk:如何解决此警告

时间:2011-01-31 10:42:20

标签: iphone objective-c

嗨,我正在与Twitter合作,在此将有两个类,用于在表格中显示推文

查看和检索表格视图的字符串,如用户照片,屏幕名称,用户名和日期

一个类是MyTweetViewController.h //我也在导入Tweet类

,下一个是Tweet.h类

//this line i am getting warning i.e NO initWithTweetDictionary method not found,

Tweet *tweet =[[Tweet alloc] initWithTweetDictionary:tweetDict];



- -(void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier 

// this is delegate for MGTwitter for retrieving information of user

{
    NSLog(@"Statuses Receives: %@",statuses);

       {
        tweetArray = [[NSMutableArray alloc] init];

        for(NSDictionary *tweetDict in statuses) 

        {

Tweet *tweet =[[Tweet alloc] initWithTweetDictionary:tweetDict];// here i am getting 

warring  i.e NO initWithTweetDictionary method not found, 

            [tweetArray addObject:tweet];

            [tweet release];

        }
    }


    [self.tweetsTableView reloadData];
}


////Tweet.h

#import <UIKit/UIKit.h>


@interface Tweet : NSObject {

    NSDictionary *contentsTweet;

}

-(NSString*)userName;

-(NSString*)tweet;

-(NSString*)image_url;

-(NSString*)created_at;



@end

///Tweet.m

#import "Tweet.h"


@implementation Tweet

-(id)initWithTweetDictionary:(NSDictionary*)_contentsTweet {

    if(self = [super init]) {

        contentsTweet = _contentsTweet;

        [contentsTweet retain];
    }

    return self;
}

-(NSString*)userName {

    NSDictionary * dic = (NSDictionary*)[contentsTweet objectForKey:@"user"];

    return [dic objectForKey:@"name"];
}

-(NSString*)tweet {

    return [contentsTweet objectForKey:@"text"];
}
-(NSString*)image_url {

    NSDictionary * dic = (NSDictionary*)[contentsTweet objectForKey:@"user"];

    return [dic objectForKey:@"profile_image_url"];

}

- (void)dealloc {

    [contentsTweet release];

    [super dealloc];
}


@end

请建议我

谢谢

1 个答案:

答案 0 :(得分:2)

在Tweet.h中,您必须声明-(id)initWithTweetDictionary:(NSDictionary*)_contentsTweet; 为了使警告消失。

@interface Tweet : NSObject {
    NSDictionary *contentsTweet;
}

-(id)initWithTweetDictionary:(NSDictionary*)_contentsTweet;
-(NSString*)userName;
-(NSString*)tweet;
-(NSString*)image_url;
-(NSString*)created_at;

@end