开发者

How to compare Array index according to button tag?

indexpath.row for array                          b.tag

0 Date1                                          0
1 india                                          1
2 pakistan                                       2
3 Date2                                          3
4 Zimbabwe                                       3
5 England                                        4
6 Date3                                          6
7 Australia                                      5
8 Westindes                                      6
9 Date3                                          9
10 Shrilanka                  开发者_开发百科                   7
11 southAfrica                                   8

Here, indexpath.row for array is my Array. Now when i click on b.tag=3 then I want to display Array index 4th value i.e Zimbabwe and not the Date2 which is on array index 3. Similarly, for b.tag=6 and b.tag=9. For that following is the code that i have written.

please take a look...

if (b.tag!=[arr objectAtIndex:path])
{
   NSLog(@"Team name %@",[arr objectAtIndex:b.tag]);
}

From the above code my first record result is coming right i.e of b.tag=1 and b.tag=2,but not for others because my Array index and b.tag are different. So please help me out of this.

Any help will be appreciated.

Thanks in Advance.


Why not change the contents of the array to better reflect your button tags?

It seems you have two different data types represented by one array, split them out:

NSArray *teamArray = [NSArray arrayWithObjects:@"India", @"Pakistan", @"Zimbabwe", @"England", @"Australia", @"WestIndies", @"Shrilanka", @"SouthAfrica", nil];

NSLog(@"Team name %@",[teamArray objectAtIndex:b.tag]);


It seems you have passed a same tag for two instance of buttons why don't you just set the tag like this b.tag = indexPath.row?.

UPDATE

use this code -

NSInteger index = b.tag;
if(b.tag != 0 && b.tag %3 == 0){
    index = index+1;
}

 NSLog(@"Team name %@",[arr objectAtIndex:index]);

Update

I have tested this code and it's showing index = 4 when index was 4 it's not increasing the index value

self.view.tag = 4;
NSInteger index = self.view.tag;

if(index%3 == 0 && index != 0)
{
    index = index+1;
    NSLog(@"Index Value Is %d",index);
}
NSLog(@"Index Value Is %d",index);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜