嗨,我正在开发一个具有图像更新功能的iOS。要使用NSURLConnectionDelegate
和setDatasource
在tableview
和php
的帮助下将图片带到json
,我正在尝试为此提供详细视图选项我的表视图在这方面很艰难,请帮助我。
setdatasource
编码 imagecell.m
-(void)setDataSource:(image *)inImageObj
{
self.decriptionLabel.text = inImageObj.desp;
NSURL *url = [NSURL URLWithString:inImageObj.img];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
{
[self.responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
UIImage *image = [UIImage imageWithData:self.responseData];
self.thumbImageView.image = image;
}
这是我用来查看表格 view.m
中的图片的代码-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *cellIdentifier =@"Cell";
imgpoliticalCell *cell =(imgpoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell== nil) {
cell = [[imgpoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setDataSource:[imgevery objectAtIndex:indexPath.row]];
return cell;
}
现在我想查看detailviewcontroller
中的图片和说明。我尝试使用segue我无法正常使用
detailviewcontroller.h 文件
@interface DetailpoliticalViewController : UIViewController
@property (strong,nonatomic) UIImage * image;
@property (strong,nonatomic) NSString * data;
@property (strong, nonatomic) IBOutlet UIImageView *imageview;
@property (strong, nonatomic) IBOutlet UILabel *view;
这是我在 detailviewcontroller.m 文件中使用的代码
@implementation DetailpoliticalViewController
@synthesize imageview,view;
@synthesize image,data;
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageview.image = self.image;
self.view.text= self.data;
// Do any additional setup after loading the view.
}
这是我在表视图控制器中使用的push segue代码
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Detailsegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
NSIndexPath *indexPath =[self.mytableview indexPathForCell:(UITableViewCell *) sender];
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
现在我无法在详细视图控制器中查看图像和描述我收到了nil异常错误
请任何人建议某种方式查看详细信息
提前致谢
答案 0 :(得分:0)
使用
NSIndexPath *indexPath =[self.mytableview indexPathForSelectedRow];
而不是
NSIndexPath *indexPath =[self.mytableview indexPathForCell:(UITableViewCell *) sender];
答案 1 :(得分:0)
您可以通过实施以下两种方法来实现这一目标:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"Detailsegue" sender:indexPath];
}
及以下方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"Detailsegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
NSIndexPath *indexPath = (NSIndexPath *)sender;
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
}
答案 2 :(得分:0)
检查一下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier: @"DetailSegue" sender: self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"DetailSegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
indexPath = [self.tableView indexPathForSelectedRow];
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
}
查看本教程LINK 1