我有2個視圖控制器,我將數據從1傳遞到2,但2中的NSString是空的(null)我做錯了什麼?從視圖控制器傳遞的數據返回null
視圖控制器1 .M
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"Method 1");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Method 2");
NSLog(@"%lu", (unsigned long)[allPosts count]);
return [[[allPosts objectForKey:@"posts"] valueForKey:@"title"] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Method 3");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", [[[allPosts objectForKey:@"posts"] valueForKey:@"title"] objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
OldPostViewController *vc = [[OldPostViewController alloc] init];
NSString *url = [NSString stringWithFormat:@"server/app/post.php?id=%@", [[[allPosts objectForKey:@"posts"] valueForKey:@"id"] objectAtIndex:indexPath.row]];
vc.postURL = url;
NSLog(@"%@", vc.postURL);
[self performSegueWithIdentifier:@"viewPost" sender:self];
}
視圖控制器2·H
#import <UIKit/UIKit.h>
@interface OldPostViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *blogView;
@property (strong, nonatomic) NSString *postURL;
@end
視圖控制器2的.m
NSLog(@"URL: %@", _postURL);
NSString *fullURL = _postURL;
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[blogView loadRequest:requestObj];
請任何人告訴我我可以做什麼,因爲我嘗試了所有可以在Google上找到的解決方案& Stackoverflow
您好,感謝快速回復,我已經實現了didSelectRowAtIndexPath方法方法和一切工作只是視圖不不顯示屏幕只是黑色是什麼意思。 –
@ user2802926:聲明'vc'屬性,而不是本地實例,然後嘗試 –
嗨,我將它初始化爲本地屬性,並且在嘗試呈現視圖控制器時崩潰 –