objective c - I need to make a favorite button and change the image when click -
I'm creating a button with a star image and the need to change the image click I click I when button Likes to do and then click on the favorite click.
Here is the code
- (UITableViewCell *) Table Views: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) Indekspath {UITableViewCell * cell = [Teblwu qualified Dekyuvr Riug Cell woth identifier: @ "cell"]; If (cell == blue) {cell = [[Uaitiblwugel light] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @ "cell"]; } FavButton = [UIButtonTypeCustom] with UIButton Button; [FavButton addTarget: self action: @ selector (Btnclait :) Control Event: UIControlEventTouchUpInside]; [Favibtn Setbakgroundpradrshn [Uaimej enrolled Image: @ "Sterds paging"] Forest: Uaikantolstetanorml]; FavButton.frame = CGRectMake (200, 90, 20, 25); [Cell. Add contentviewsviewview: FAVButtons]; Return cell; }
You must store the state somewhere, this is usually the array indexed by indexpath (Your dataset), which I have seen that you do not use. In addition to changing the image on click, you have to set state to the array. The method clicked in the button, until you can not reach the UITableViewCell button clicked, find the position in the table, repeat the review. Now you can change the indicator of data in the array. After that, just before setting the background image, just check the status of something like this: MyData * dta = self.myData [indexPath.row]; If (Dtakfevret) [Fwbutton Setbakgruundimage [Uiimage Imagenmed: @ "Stardeskpang"] Forstte: Uikantrolstetenorml]; Else [favButton setBackgroundImage: [UIImage imageNamed: @ "stardes2.png"] forState: UIControlStateNormal];
Comments
Post a Comment