当表视图部分按钮pressed如何加载不同的数组? [英] how to load Different Array when table view Section Button Pressed?

查看:141
本文介绍了当表视图部分按钮pressed如何加载不同的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手在iOS开发我正在开发一个应用程序的杂志。在我使用的tableview它包含两个部分,每个部分都有 preVIEW 按钮一样显示在下面的形象。 我想显示不同的图像时, preVIEW 按钮pssed $ p $。图像阵列从JSON解析。在这里,所有图像都在数组(此数组包含图像阵列)。因此,对于第一部分我写了一个code像

I am newbie in iOS development I am developing a magazine application. In that I have used tableview which contains two section and each section has PREVIEW button like shown in below image. I would like to show different images when PREVIEW button is pressed. Image array is parsed from JSON. Here all images are in array (This array contains array of images). So for first section I wrote a code like

NSDictionary *dict=[self.imagesa objectAtIndex:0];

但对于第二部分两种细胞是有它使用相同的自定义单元格。我现在迷茫了如何显示第二个对象的数组时的tableview的第二部分 preVIEW 按钮pssed $ P $和同样的方式加载第三方图像阵列时,第二部分的第二个单元格 preVIEW 按钮pssed $ p $。如果我让不同的Xibs每个按钮,然后在将来如果添加了新的细胞,然后将无法正常工作。请给我,这里是Web服务的链接 WebService的链路解决方案

But for second section two cell are there which uses same custom Cell. I am now confused that How to show second object array when tableview's second section PREVIEW button is pressed and same way load third image array when second section's second cell Preview button is pressed. If I make different Xibs for each button then in future if new cell is added then it will not work. Please give me solution for that here is web services link WebService link

我想显示第一-demopage:数组第一个单元格和第二-demopage:为第二和高达表视图的最后一个单元格。怎么可能,请给我的解决方案。

I would like to show First -demopage: array for first cell and Second -demopage: for second and upto last cell of table view. How it possible please give me solution.

下面我preVIEW按钮code

Here my Preview Button Code

UIButton *preview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        preview.frame = CGRectMake(112,95, 89, 25);
        preview.backgroundColor=[UIColor colorWithRed:229.0/256.0 green:229.0/256.0 blue:229.0/256.0 alpha:1.0f];
        [preview setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [preview setTitleColor:[UIColor colorWithRed:229.0/256.0 green:229.0/256.0 blue:229.0/256.0 alpha:1.0] forState:UIControlStateHighlighted];
        [preview setTitle:@"PREVIEW" forState:UIControlStateNormal];
        [preview.titleLabel setFont:[UIFont fontWithName:@"RobotoCondensed-Bold" size:14.0f]];
        [cellTwo addSubview:preview];
        [preview addTarget:self action:@selector(showPreviewSeondSection:)forControlEvents:UIControlEventTouchUpInside];

        preview.tag=indexPath.row;

和其作为

-(IBAction)showPreviewSeondSection:(id)sender
{
UIButton *button = (UIButton *)sender;
NSInteger row = button.tag;
NSLog(@"Tag of button %d",row);
}

但现在我搞不清我怎么我demopage链接数组加载到其他视图控制器,当我第Row按钮$ P $索引pssed。

But now i am Confuse how i load my demopage link array into another view Controller when my Section Row Button pressed at index.

现在我更新我的问题是我第一次从我的主阵列分析我-demopage键像为

Now i update my Question as first i parsed my -demopage key from my main array like as

if (responsedata.length > 0)
{
    NSError* error;

    self.json = [NSJSONSerialization JSONObjectWithData:responsedata options:kNilOptions error:&error];
    if ([[_json objectForKey:@"data"] isKindOfClass:[NSArray class]])
    {
        NSArray *arr = (NSArray *)[_json objectForKey:@"data"];
        [self.imageArray addObjectsFromArray:arr];
        [self.storeViewTable reloadData];
    }
    self.storeViewTable.hidden=FALSE;
    }
    for (index=0; index<[self.imageArray count]; index++)
    {
        NSDictionary *imgDict = [self.imageArray objectAtIndex:index];
        if([imgDict count]>0)
        {
            NSMutableArray *imgsLinkArray = [imgDict objectForKey:@"demopage"];
            self.imagesa = imgsLinkArray;
        }
    }

和我设置为我泰伯维单元格按钮标记为

and i set a tag for my Tableview Cell Button as

preview.tag=indexPath.row;

和它的作用就像为

-(IBAction)showPreviewSeondSection:(id)sender
{
UIButton *button = (UIButton *)sender;
NSInteger row = button.tag;
for (index=0; index<[self.imagesa count]; index++)
{
if (row == 1)
{
    PreviewViewController *preview=[[PreviewViewController alloc]initWithNibName:@"PreviewViewController" bundle:nil];
    preview.imagesa=self.imagesa;
    [self presentViewController:preview animated:YES completion:nil];
    NSLog(@"Preview array %@",preview.imagesa);
}
}
}

然后打印我-demopage数组最后指数滚动型我,请给我解决方案如何我preSS第一个按钮,然后我拿到第一个索引值,当我preSS第二个单元格按钮,然后我想打印第二指数值。

then it print my -demopage array Last index in my Scrollview please give me Solution for how i press first button then i get First index value and when i press Second cell button then i want to Print second index value.

推荐答案

在您的按钮preSS方法,

In your button press method,

-(IBAction)showPreviewSeondSection:(id)sender
{
      CGPoint rootViewPoint = [sender.superview convertPoint:CGRectZero toView: self.storeViewTable];
      NSIndexPath *indexPath = [self.storeViewTable indexPathForRowAtPoint:rootViewPoint];

     PreviewViewController *preview=[[PreviewViewController alloc]initWithNibName:@"PreviewViewController" bundle:nil];
     preview.imagesa=self.imagesa[indexPath.row];
     [self presentViewController:preview animated:YES completion:nil];

}

您可以得到那么indexPath从阵列访问对象,并传递到下一个的ViewController

You can get the indexPath then access the object from your array and pass into next ViewController

这篇关于当表视图部分按钮pressed如何加载不同的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆