我希望你們能夠幫助我在我的代碼中加載來自網站的數據。讓我們先從代碼:TableView沒有更新
-(void)viewDidLoad
{
[self loadDataFromUrl];
}
-(void)loadDataFromUrl {
NSString *myUrl = [NSString stringWithFormat:@"http://WebSite/PhpFiles/File.php"];
NSURL *blogURL = [NSURL URLWithString:myUrl];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization
JSONObjectWithData:jsonData options:0 error:&error];
for (NSDictionary *bpDictionary in dataDictionary) {
HotelObject *currenHotel = [[HotelObject alloc]initWithVTheIndex:
[bpDictionary objectForKey:@"TheIndex"] timeLineVideoUserName:
[bpDictionary objectForKey:@"timeLineVideoUserName"] timeLineVideoDetails:
[bpDictionary objectForKey:@"timeLineVideoDetails"] timeLineVideoDate:
[bpDictionary objectForKey:@"timeLineVideoDate"] timeLineVideoTime:
[bpDictionary objectForKey:@"timeLineVideoTime"] timeLineVideoLink:
[bpDictionary objectForKey:@"timeLineVideoLink"] timeLineVideoLikes:
[bpDictionary objectForKey:@"timeLineVideoLikes"] videoImage:
[bpDictionary objectForKey:@"videoImage"] timeDeviceToken:
[bpDictionary objectForKey:@"deviceToken"]];
[self.objectHolderArray addObject:currenHotel];
}
}
-(NSMutableArray *)objectHolderArray{
if(!_objectHolderArray) _objectHolderArray = [[NSMutableArray alloc]init];
return _objectHolderArray;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
return [self.objectHolderArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
HotelObject *currentHotel = [self.objectHolderArray
objectAtIndex:indexPath.row];
cell.lblID.text = currentHotel.vvTheIndex;
cell.lblName.text = currentHotel.vvUserName;
cell.lblCity.text = currentHotel.vvVideoDate;
cell.lblAddress.text = currentHotel.vvVideoLikes;
return cell;
}
上面的代碼從URL加載數據,並填補了TableView中,這一步工作的罰款。該應用程序有另一個ViewController,它是DetailsView,在DetailsView中用戶可以更新一些信息。當用戶返回到TableView時什麼都沒有發生(我的意思是數據仍然是一樣的,沒有更新)。我試圖從ViewDidAppear調用loadDataFromurl,但它不起作用。
我做了補充:
[self.tableView reloadData];
但還是同樣的結果。
她也是我的NSObject的代碼:
-(instancetype)initWithVTheIndex:(NSString *)vTheIndex
timeLineVideoUserName:(NSString *)vUserName
timeLineVideoDetails:(NSString *)vVideoDetails
timeLineVideoDate:(NSString *)vVideoDate
timeLineVideoTime:(NSString *)vVideoTime
timeLineVideoLink:(NSString *)vVideoLink
timeLineVideoLikes:(NSString *)vVideoLikes
videoImage:(NSString *)vVideoImage
timeDeviceToken:(NSString *)vDeviceToken {
self = [super init];
if(self){
self.vvTheIndex = vTheIndex;
self.vvUserName = vUserName;
self.vvVideoDetails = vVideoDetails;
self.vvVideoDate = vVideoDate;
self.vvVideoTime = vVideoTime;
self.vvVideoLink = vVideoLink;
self.vvVideoLikes = vVideoLikes;
self.vvVideoImage = vVideoImage;
self.vvDeviceToken = vDeviceToken;
}
return self;
}
我的問題是:如何從DetailsView控件移動,甚至當我拉刷新時更新的TableView。
在此先感謝
謝謝Meriw,我已經知道了 – user3741700