Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:44:44+00:00 2026-06-14T02:44:44+00:00

This is my code to show the table view inside alert view. Its working

  • 0

This is my code to show the table view inside alert view. Its working perfectly in iOS 5.1. But in iOS 6.0 it doesnt show the table view inside alert view.

UIAlertTableView.h

#import <UIKit/UIKit.h>

@class UIAlertView;

@interface UIAlertTableView : UIAlertView {
    // The Alert View to decorate
    UIAlertView *alertView;

    // The Table View to display
    UITableView *tableView;

    // Height of the table
    int tableHeight;

    // Space the Table requires (incl. padding)
    int tableExtHeight;

    id<UITableViewDataSource> dataSource;
    id<UITableViewDelegate> tableDelegate;

    NSArray *names;
    NSArray *prices;
    NSString *priceText;
    NSInteger rowsCount;
    NSInteger total;
}

@property (nonatomic, assign) id dataSource;
@property (nonatomic, assign) id tableDelegate;

@property (nonatomic, readonly) UITableView *tableView;
@property (nonatomic, assign) int tableHeight;
@property (nonatomic, assign) NSInteger total;

- (void)prepare;

@end

UIAlertTableView.m

#import "UIAlertTableView.h"

#define kTablePadding 8.0f


@interface UIAlertView (private)
- (void)layoutAnimated:(BOOL)fp8;
@end

@implementation UIAlertTableView

@synthesize dataSource;
@synthesize tableDelegate;
@synthesize tableHeight;
@synthesize tableView;

@synthesize total;

- (void)layoutAnimated:(BOOL)fp8 {
    [super layoutAnimated:fp8];
    [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y - tableExtHeight/2, self.frame.size.width, self.frame.size.height + tableExtHeight)];

    // We get the lowest non-control view (i.e. Labels) so we can place the table view just below
    UIView *lowestView;
    int i = 0;
    while (![[self.subviews objectAtIndex:i] isKindOfClass:[UIControl class]]) {
        lowestView = [self.subviews objectAtIndex:i];
        i++;
    }

    CGFloat tableWidth = 262.0f;

    tableView.frame = CGRectMake(11.0f, lowestView.frame.origin.y + lowestView.frame.size.height + 2 * kTablePadding, tableWidth, tableHeight);

    for (UIView *sv in self.subviews) {
        // Move all Controls down
        if ([sv isKindOfClass:[UIControl class]]) {
            sv.frame = CGRectMake(sv.frame.origin.x, sv.frame.origin.y + tableExtHeight, sv.frame.size.width, sv.frame.size.height);
        }
    }

}

- (void)show{
    self.total = 0;
    [self prepare];
    [super show];
}

- (NSInteger)tableView:(UITableView *)alerttableView numberOfRowsInSection:(NSInteger)section
{
/*
code to show some app data in rows
    //    NSMutableDictionary *rowsUponDict = [AppDelegate productsPFObjectDictionaryAppDelegate];
    NSMutableArray *productsNames = [AppDelegate productsPFObjectDictionaryNamesAppDelegate];

    //    rowsCount = [[rowsUponDict allKeys] count];
    rowsCount = [productsNames count];
    NSLog(@"rowsUponDict count: %d",rowsCount);
    return rowsCount+1;
*/
return 1;
}

- (UITableViewCell *)tableView:(UITableView *)alerttableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"LazyTableCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

/*
code to show some app data in rows

    if (indexPath.row == rowsCount) {
        cell.textLabel.text = @"Total Amount:";
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",self.total];
    }
    else {
        cell.textLabel.text = [names objectAtIndex:indexPath.row];
        priceText = [NSString stringWithFormat:@"%@", [prices objectAtIndex:indexPath.row]];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"Rs.%@",priceText];
    }
*/

    return cell;
}

- (void)prepare {
    if (tableHeight == 0) {
        tableHeight = 250.0f;
    }
    /*
calculation os some app data

    NSInteger priceInt;
    names = [[NSArray alloc] initWithArray:[AppDelegate productsPFObjectDictionaryNamesAppDelegate]];
    NSLog(@"Names: %@",names);
    prices = [[NSArray alloc] initWithArray:[AppDelegate productsPFObjectDictionaryPricesAppDelegate]];
    NSLog(@"prices: %@",prices);

    for (int i=0; i<[prices count]; i++) {
        priceText = [NSString stringWithFormat:@"%@", [prices objectAtIndex:i]];
        priceInt = [priceText integerValue];
        self.total = self.total + priceInt;
        NSLog(@"tatal: %d",self.total);
    }
    */
    tableExtHeight = tableHeight + 2 * kTablePadding;

    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f) style:UITableViewStylePlain];
    tableView.delegate = tableDelegate;
    tableView.dataSource = dataSource;



    [self addSubview:tableView];
//  [self insertSubview:tableView atIndex:0];

    [self setNeedsLayout];
}

- (void)dealloc {
    [tableView release];
    [super dealloc];
}

@end

This is how I use it

UIAlertTableView *popUpCartItems = [[UIAlertTableView alloc] initWithTitle:@"Cart" message:nil delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"CheckOut",nil];
popUpCartItems.tableDelegate = popUpCartItems;
popUpCartItems.dataSource = popUpCartItems;
popUpCartItems.tableHeight = 132;
[popUpCartItems show];

Any help is greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:44:45+00:00Added an answer on June 14, 2026 at 2:44 am

    Check the following link

    https://github.com/simonb/SBTableAlert

    I tested on both iOS 5.0 and iOS 6.0 and its work perfectly for me.

    You just need to do download that code and use in your project.

    Hope this will help you !!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My brother wrote this code for me to show an example of polymorhism. But
I'm working on this app, but somehow, its not returning any rows in my
i was able to hide row on Table View Cell by using this code
<video id=myVideo src=2.mp4 controls= tabindex=0>decoder not found</video> this code show ' decoder not found'
from this code will show in original color how can i change it to
I have this code to show a map using the Virtual Earth API: <script
Im using this code to show/hide a div: <a href=# class=show_hide>Show/hide</a> <div class=slidingDiv> My
I've written this code to show a prompt before a form is submitted. If
How would I modify this code to show the animated movement (item moving from
I'm using this jquery code to show and hide divs on my page. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.