gpambrozio / BlockAlertsAnd-ActionSheets

Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot
http://codecropper.com/2012/01/replicating-tweetbots-alerts-and-action-sheets/
MIT License
1.41k stars 268 forks source link

How do you use BlockTableAlertView? #53

Closed sabernar closed 11 years ago

sabernar commented 11 years ago

There is no example, and the class is not very intuitive. Can you post an example?

barrettj commented 11 years ago

Implement the following like they were your table data source:

@property (readwrite,copy)  TableAlertIndexBlock didSelectRow;
@property (readwrite,copy)  TableAlertCellSourceBlock cellForRow;
@property (readwrite,copy)  TableAlertNumberOfRowsBlock numberOfRowsInTableAlert;
sabernar commented 11 years ago

Can you provide an example of the TableAlertCellSourceBlock cellForRow method?

jmyrose commented 11 years ago

Here's the code I used that worked:

BlockTableAlertView *listView = [[BlockTableAlertView alloc] initWithTitle:@"Available Boards" message:@"Add      webpage to board:"];
listView.type = BlockTableAlertTypeSingleSelect;
listView.numberOfRowsInTableAlert = ^(BlockTableAlertView* alertView){
    return [boardsArray count];
};
listView.cellForRow = ^(BlockTableAlertView* alertView, NSInteger row){
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [alertView.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Set the data for this cell:
    NEBoardsListItem *board = [boardsArray objectAtIndex:row];
    cell.textLabel.text = board.title;

    return cell;
};
 listView.didSelectRow = ^(BlockTableAlertView* alertView, NSInteger row){
    NSLog(@"Selected row: %d", row);
};
jmyrose commented 11 years ago

Also, just added a pull request with a demo of this.