Mit dem folgenden Code, ich versuche, die Likes Video zu bekommen, ich bekomme die Anzahl in Array und ich möchte das auf eine Schaltfläche Titel alles funktioniert gut.Wie wird der Indexpfad zu einer Schaltfläche festgelegt?
Ich habe eine Schaltfläche Aktion und damit kann ich die Likes zählen auf diese Schaltfläche zeigen. Aber mein Problem ist, dass ich mit diesem Code die gleiche Anzahl wie in allen Clips in der Tabellenansicht bekomme, also möchte ich genau wie zählen für die jeweilige Schaltfläche erhalten, wie würde ich das tun.
// here is how i am getting like count
- (void)getcat
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"ClipTable"];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ClipTable" inManagedObjectContext:self.managedObjectContext];
fetchRequest.resultType = NSDictionaryResultType;
fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"total_likes"]];
fetchRequest.returnsDistinctResults = YES;
NSArray *dictionaries = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
NSLog (@"total_likes: %@",dictionaries);
[NSString stringWithFormat:@"%@",[dictionaries valueForKey:@"total_likes"]];
self.devices =[[NSMutableArray alloc]init];
self.devices=[dictionaries mutableCopy];
NSLog(@"cat1 is%@",self.devices);
}
Und das ist, wie ich wie Graf bin Anzeige auf die Schaltfläche
- (IBAction)likeButtonAction:(id)sender
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
NSManagedObject *managedObject = [self.devices objectAtIndex:indexPath.row];
NSString *likes = [NSString stringWithFormat:@"%@",[managedObject valueForKey:@"total_likes"]];
[sender setTitle:likes forState:UIControlStateNormal];
}
Code für cellForRowAtIndexPath ist unter diesem Code enthält nicht meine beliebige Taste Code auf die Schaltfläche Aktion likeButtonTapped getrennt ist
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
// Fetch Record
NSManagedObject *record = [self.fetchedResultsController objectAtIndexPath:indexPath];
//this button is different one
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(208,96, 100, 30)];
[btn addTarget:self action:@selector(yourButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; btn.tag = indexPath.row;
[btn setImage:[UIImage imageNamed:@"btn-details.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:btn];
NSLog(@"sender.tag cell is%ld ",(long)btn.tag);
}
see my debugger output
indexpath is0
2016-06-10 19:20:31.435 freejournlaist[4159:134867] indexpath is4
2016-06-10 19:20:31.436 freejournlaist[4159:134867] sender.tag cell is4
2016-06-10 19:20:33.351 freejournlaist[4159:134867] indexpath is5
2016-06-10 19:20:33.352 freejournlaist[4159:134867] sender.tag cell is5
2016-06-10 19:20:34.140 freejournlaist[4159:134867] indexpath is6
2016-06-10 19:20:34.141 freejournlaist[4159:134867] sender.tag cell is6
2016-06-10 19:20:35.506 freejournlaist[4159:134867] indexpath is7
2016-06-10 19:20:35.507 freejournlaist[4159:134867] sender.tag cell is7
2016-06-10 19:20:35.888 freejournlaist[4159:134867] indexpath is8
2016-06-10 19:20:35.889 freejournlaist[4159:134867] sender.tag cell is8
2016-06-10 19:20:36.139 freejournlaist[4159:134867] indexpath is9
2016-06-10 19:20:36.140 freejournlaist[4159:134867] sender.tag cell is9
2016-06-10 19:20:36.475 freejournlaist[4159:134867] indexpath is10
2016-06-10 19:20:36.476 freejournlaist[4159:134867] sender.tag cell is10
2016-06-10 19:20:38.201 freejournlaist[4159:134867] indexpath is6
2016-06-10 19:20:38.202 freejournlaist[4159:134867] sender.tag cell is6
2016-06-10 19:20:38.701 freejournlaist[4159:134867] indexpath is5
2016-06-10 19:20:38.702 freejournlaist[4159:134867] sender.tag cell is5
2016-06-10 19:20:39.267 freejournlaist[4159:134867] indexpath is4
2016-06-10 19:20:39.268 freejournlaist[4159:134867] sender.tag cell is4
2016-06-10 19:20:40.684 freejournlaist[4159:134867] indexpath is3
2016-06-10 19:20:40.685 freejournlaist[4159:134867] sender.tag cell is3
2016-06-10 19:20:40.837 freejournlaist[4159:134867] indexpath is2
2016-06-10 19:20:40.839 freejournlaist[4159:134867] sender.tag cell is2
2016-06-10 19:20:41.152 freejournlaist[4159:134867] indexpath is1
2016-06-10 19:20:41.153 freejournlaist[4159:134867] sender.tag cell is1
2016-06-10 19:20:41.952 freejournlaist[4159:134867] indexpath is0
2016-06-10 19:20:41.954 freejournlaist[4159:134867] sender.tag cell is0
2016-06-10 19:21:02.915 freejournlaist[4159:134867] indexpath is3
2016-06-10 19:21:02.916 freejournlaist[4159:134867] sender.tag cell is3
2016-06-10 19:55:38.055 freejournlaist[4326:144151] total_likes: (
{
"total_likes" = 1;
},
{
"total_likes" = 5;
},
{
"total_likes" = 2;
},
{
"total_likes" = 0;
},
{
"total_likes" = 4;
},
{
"total_likes" = 3;
},
{
"total_likes" = 6;
},
{
"total_likes" = 115;
}
)
2016-06-10 19:55:38.055 freejournlaist[4326:144151] cat1 is(
{
"total_likes" = 1;
},
{
"total_likes" = 5;
},
{
"total_likes" = 2;
},
{
"total_likes" = 0;
},
{
"total_likes" = 4;
},
{
"total_likes" = 3;
},
{
"total_likes" = 6;
},
{
"total_likes" = 115;
}
wo u dieser Schaltfläche likeButtonAction genannt –
in einem tabelView Individuellen Handy @Anbu .Karthik – vicky
NSLog die '[Absender-Tag]' und sehen, was es gibt .. – NSPratik