Created
January 6, 2011 05:18
-
-
Save marshluca/767536 to your computer and use it in GitHub Desktop.
UIActivityIndicator as Accessory View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SPINNER_SIZE 25 | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; | |
// Get center of cell (vertically) | |
int center = [cell frame].size.height / 2; | |
// Size (width) of the text in the cell | |
CGSize size = [[[cell textLabel] text] sizeWithFont:[[cell textLabel] font]]; | |
// Locate spinner in the center of the cell at end of text | |
[spinner setFrame:CGRectMake(size.width + SPINNER_SIZE, center - SPINNER_SIZE / 2, SPINNER_SIZE, SPINNER_SIZE)]; | |
[[cell contentView] addSubview:spinner]; | |
[spinner startAnimating]; | |
[spinner release]; | |
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
UIActivityIndicatorView *activityView = | |
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; | |
[activityView startAnimating]; | |
[cell setAccessoryView:activityView]; | |
[activityView release]; | |
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment