嗨我想從我的在線服務器加載數據到視圖控制器,但我得到的問題很少。使用nsobject和json我試圖加載我的視圖控制器。我堅持將nsobject連接到我在故事曲目中的標籤。如何從視圖控制器中的服務器加載數據IOS
這是nsboject代碼.h文件和M文件
@interface vote : NSObject
@property (nonatomic,strong) NSString * question;
@property (nonatomic,strong) NSString * choose1;
@property (nonatomic,strong) NSString * choose2;
-(id) initWithquestion: (NSString *) qut andchoose1: (NSString *) ch andchoose2: (NSString *) cho;
這是我在viewcontorller M檔都用於獲取DATAS代碼。
#define getDataURL @"http://localhost/poll/view.php"
@implementation pollingpoliticalViewController
@synthesize que,cho1,cho2;
@synthesize json,pollarray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//vote *cnnt = [pollarray ];
// Do any additional setup after loading the view.
}
-(void) retrieveData
{
NSURL * url =[NSURL URLWithString:getDataURL];
NSData * data=[NSData dataWithContentsOfURL:url];
json =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
pollarray = [[NSMutableArray alloc]init];
for (int i=0; i<json.count; i++) {
NSString * dd =[[json objectAtIndex:i]objectForKey:@"ques"];
NSString * plae= [[json objectAtIndex:i]objectForKey:@"choss1"];
NSString * ti =[[json objectAtIndex:i]objectForKey:@"choss2"];
vote *myarray =[[vote alloc]initWithquestion:dd andchoose1:plae andchoose2:ti];
[pollarray addObject:myarray];
}
}
IM卡與可變數組的標籤在我看來控制器,請有人建議天氣的連接,這是正確的方式做或我必須做的DATAS連接到我的視圖控制器的..
在tableview中,我們使用像我們這樣使用:
fieldpolitical * cunt=[eventarray objectAtIndex:indexPath.row];
detailvc.detail = cunt.title;
detailvc.pla = cunt.place;
detailvc.tim = cunt.time;
detailvc.dat = cunt.date;
// detailvc.stott
我想要做同樣的事情對我的控制程序圖
感謝
您是否使用了一個使用標籤創建視圖控制器的故事板?如果是這樣,視圖控制器的自定義類是否設置爲「pollingpoliticalViewController」,標籤Outlets是否設置? – bobnoble
s oultllets everthing很好@bobnoble – kumar