Ios 在TableViewController中将TapGestureRecognitor与profileimage一起使用

Ios 在TableViewController中将TapGestureRecognitor与profileimage一起使用,ios,objective-c,uitableview,tableview,uitapgesturerecognizer,Ios,Objective C,Uitableview,Tableview,Uitapgesturerecognizer,下午好 我正在尝试实现一个“查看用户配置文件”按钮,它将显示一个包含用户信息的新ViewController。我在按下图像时在图像配置文件上实现了TapGestureRecognitor(它是TableViewController) 主要问题是,当我按下用户图像时,它显示了错误的ProfileViewController,因为当我按下另一行时,我的TableViewController似乎没有更新@username(它显示了我看到的最新配置文件) 我已经尝试了很多教程,但在任何情况下都不起作用,

下午好

我正在尝试实现一个“查看用户配置文件”按钮,它将显示一个包含用户信息的新ViewController。我在按下图像时在图像配置文件上实现了TapGestureRecognitor(它是TableViewController)

主要问题是,当我按下用户图像时,它显示了错误的ProfileViewController,因为当我按下另一行时,我的TableViewController似乎没有更新@username(它显示了我看到的最新配置文件)

我已经尝试了很多教程,但在任何情况下都不起作用,因为每当我按下配置文件图像时,它都会显示(我已经测试过)错误的用户名

如何将用户名更新为我按下的用户名?

查找我的XCode的图像:

这是我的TableViewController.m(它在@“segueprofile”中)

//
//CarTableViewController.m
//TableViewStory
//
#导入“CarTableViewController.h”
#导入“CarTableViewCell.h”
#导入“CarTableViewController.h”
#导入“CarDetailViewController.h”
#导入“OtherProfileUserViewController.h”
#进口
#进口
#导入“SSKeychainQuery.h”
#导入“SSKeychain.h”
#导入“SBJson.h”
@接口NSURLRequest(DummyInterface)
+(BOOL)允许任何httpscertificateforhost:(NSString*)主机;
+(void)setAllowsAnyHttpSCCertificate:(BOOL)允许主机:(NSString*)主机;
@结束
@接口CarTableViewController()
@结束
@CarTableViewController的实现
@合成卡马克=_卡马克;
@合成carModels=_carModels;
@合成carImages=\u carImages;
@合成like=_like;
@综合喜欢=_喜欢;
@综合评论=_评论;
@综合用户名=_用户名;
@综合加油机=_加油机;
@合成profileImage=\u profileImage;
-(无效)viewDidLoad
{
[超级视图下载];
[自我获取];
[self.tableView重载数据];
//初始化刷新控件。
self.refreshControl=[[UIRefreshControl alloc]init];
//self.refreshControl.backgroundColor=[UIColor blackColor];
//self.refreshControl.tintColor=[UIColor-whiteColor];
[self.refreshControl addTarget:self
操作:@selector(fetchJson)
forControlEvents:UIControlEventValueChanged];
}
-(无效)视图将显示:(BOOL)动画
{
self.navigationController.navigationBar.hidden=是;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
//返回节中的行数。
返回[_jsonarraycount];
}
-(UITableView单元格*)tableView:(UITableView*)tableView单元格用于行索引路径:(NSIndexPath*)索引路径
{
静态NSString*CellIdentifier=@“carTableCell”;
CarTableViewCell*单元格=[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
单元格=[[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.likeButton.tag=anIndexPath.row;
//配置单元格。。。
cell.makeLabel.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“id”];
cell.likes.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“likes”];
cell.comments.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“comments”];
cell.username.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“username”];
cell.refuer.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“user\u ref”];
cell.modelabel.text=[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“user”];
NSURL*imageURL=[NSURL URLWithString:[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“imagen”];
[cell.carImage setImageWithURL:imageURL占位符图像:[UIImage ImageName:@“imagen”]选项:SDWebImageRefreshCached];
NSURL*imageURL2=[NSURL URLWithString:[[u jsonArray objectAtIndex:anIndexPath.row]valueForKey:@“image”];
[cell.profileImage setImageWithURL:imageURL2
占位符图像:[UIImage ImageName:@“图像”]
选项:SDWebImageRefreshCached];
返回单元;
}
-(void)fetchJson{
self.carModels=[[NSMutableArray alloc]init];
self.carMakes=[[NSMutableArray alloc]init];
self.carImages=[[NSMutableArray alloc]init];
self.likes=[[NSMutableArray alloc]init];
self.comments=[[NSMutableArray alloc]init];
调度队列=调度获取全局队列(调度队列优先级默认为0);
调度异步(队列^{
NSString*urlString=[NSString stringWithFormat:@]http://webiste.com/service.php"];
NSURL*url=[NSURL URLWithString:urlString];
NSData*data=[NSData dataWithContentsOfURL:url];
n错误*错误;
[_jsonaryremoveallobjects];
_jsonArray=[NSJSONSerialization
JSONObjectWithData:数据
选项:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves
错误:&错误];

对于(int i=0;i)您的代码不显示您添加了点击手势的位置。还显示了点击手势的选择器。i@FawadMasud,我已将点击手势识别器连接到故事板中的图像配置文件。您需要故事板的更多信息或屏幕截图吗?谢谢。您能给我
performsguewithidentifier
方法的内容吗?
//
//  CarTableViewController.m
//  TableViewStory
//

#import "CarTableViewController.h"
#import "CarTableViewCell.h"
#import "CarTableViewController.h"
#import "CarDetailViewController.h"
#import "OtherProfileUserViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <Security/Security.h>
#import "SSKeychainQuery.h"
#import "SSKeychain.h"
#import "SBJson.h"

@interface NSURLRequest (DummyInterface)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;

+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;

@end

@interface CarTableViewController ()

@end

@implementation CarTableViewController

@synthesize carMakes = _carMakes;
@synthesize carModels = _carModels;
@synthesize carImages = _carImages;

@synthesize like = _like;
@synthesize likes = _likes;
@synthesize comments = _comments;
@synthesize username = _username;
@synthesize refuser = _refuser;
@synthesize profileImage = _profileImage;

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self fetchJson];

    [self.tableView reloadData];

    // Initialize the refresh control.
    self.refreshControl = [[UIRefreshControl alloc] init];
    //self.refreshControl.backgroundColor = [UIColor blackColor];
    //self.refreshControl.tintColor = [UIColor whiteColor];
    [self.refreshControl addTarget:self
                            action:@selector(fetchJson)
                  forControlEvents:UIControlEventValueChanged];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_jsonArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)anIndexPath
{
    static NSString *CellIdentifier = @"carTableCell";

    CarTableViewCell *cell = [tableView
                              dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[CarTableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
    }

    cell.likeButton.tag = anIndexPath.row;

    // Configure the cell...
    cell.makeLabel.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"id"];
    cell.likes.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"likes"];
    cell.comments.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"comments"];
    cell.username.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"username"];
    cell.refuser.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"user_ref"];

    cell.modelLabel.text = [[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"user"];

    NSURL * imageURL = [NSURL URLWithString:[[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"imagen"]];

    [cell.carImage setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"imagen"] options:SDWebImageRefreshCached];

    NSURL * imageURL2 = [NSURL URLWithString:[[_jsonArray objectAtIndex:anIndexPath.row] valueForKey:@"image"]];

    [cell.profileImage setImageWithURL:imageURL2
                      placeholderImage:[UIImage imageNamed:@"image"]
                            options:SDWebImageRefreshCached];

    return cell;
}

-(void)fetchJson {

    self.carModels = [[NSMutableArray alloc] init];
    self.carMakes = [[NSMutableArray alloc] init];
    self.carImages = [[NSMutableArray alloc] init];
    self.likes = [[NSMutableArray alloc] init];
    self.comments = [[NSMutableArray alloc] init];

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{

        NSString * urlString = [NSString stringWithFormat:@"http://webiste.com/service.php"];
        NSURL * url = [NSURL URLWithString:urlString];
        NSData * data = [NSData dataWithContentsOfURL:url];

        NSError *error;
        [_jsonArray removeAllObjects];
        _jsonArray = [NSJSONSerialization
                      JSONObjectWithData:data
                      options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
                      error:&error];

            for(int i=0;i<_jsonArray.count;i++)
            {
                NSDictionary * jsonObject = [_jsonArray objectAtIndex:i];
                NSString* imagen = [jsonObject objectForKey:@"imagen"];
                [_carImages addObject:imagen];

                NSDictionary * jsonObject2 = [_jsonArray objectAtIndex:i];
                NSString* user = [jsonObject2 objectForKey:@"user"];
                [_carMakes addObject:user];

                NSDictionary * jsonObject3 = [_jsonArray objectAtIndex:i];
                NSString* date = [jsonObject3 objectForKey:@"date"];
                [_carModels addObject:date];
            }

        dispatch_async(dispatch_get_main_queue(), ^{
            {
                [self.tableView reloadData];
                [self.refreshControl endRefreshing];
            }});

        }
    );

    //NSLog(@"LINK ==> %@", _jsonArray);
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    //NSIndexPath *indexPath = [self tableView indexPathForCell:sender];

    //NSLog(@"LINK ==> %@", indexPath);

    if ([segue.identifier isEqualToString:@"segueprofile"]) {
        OtherProfileUserViewController *destViewController = segue.destinationViewController;
        destViewController.recipeName = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"username"];
    }
    if ([segue.identifier isEqualToString:@"segueprofile2"]) {
        OtherProfileUserViewController *destViewController = segue.destinationViewController;
        destViewController.recipeName = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"username"];
    }
    if ([[segue identifier] isEqualToString:@"ShowCarDetails"])
    {
        CarDetailViewController *detailViewController = [segue destinationViewController];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

        detailViewController.carDetailModel = [[NSArray alloc]
                                               initWithObjects:
                                               [[_jsonArray objectAtIndex:[myIndexPath row]] valueForKey:@"date"],
                                               [[_jsonArray objectAtIndex:[myIndexPath row]] valueForKey:@"id"],
                                               [[_jsonArray objectAtIndex:[myIndexPath row]] valueForKey:@"imagen"],
                                               nil];
    }
}

- (void) alertStatus:(NSString *)msg :(NSString *) title
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alertView show];
}

- (IBAction)plusOne:(UIButton *)sender {

    NSLog(@"%ld",(long)sender.tag);
}

@end