Setting uibutton frame not working - objective-c

I have values in dictionaries that will make a frame of a uibutton
tags = (
{
height = "15.513672";
text = jeans;
width = "39.808105";
x = "225.500000";
y = "265.000000";
},
{
height = "15.513672";
text = jacket;
width = "44.080078";
x = "190.000000";
y = "156.500000";
}
);
I set the frame of uibuttons with the values from the dictionaries
for (int i = 0; i<[tags count]; i++) {
NSLog(#"adding tags");
NSMutableDictionary *propertiesdict = [[NSMutableDictionary alloc] init];
propertiesdict = [[tags objectAtIndex:i] mutableCopy];
float x = [[dict objectForKey:#"x"] floatValue];
float y = [[dict objectForKey:#"y"] floatValue];
float width = [[dict objectForKey:#"width"] floatValue];
float height = [[dict objectForKey:#"height"] floatValue];
NSString *title = [dict objectForKey:#"text"];
UIButton *button = [[UIButton alloc] init];
[button setFrame:CGRectMake(x, y, width, height)];
[button setTitle:title forState:UIControlStateNormal];
button.layer.cornerRadius = 2.5;
//button.alpha = 0.9;
[button.titleLabel setFont:[UIFont systemFontOfSize:13]];
[button setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
button.tag = i;
[button addTarget:self action:#selector(tappedOnTag:) forControlEvents:UIControlEventTouchUpInside];
[tagsView addSubview:button];
}
After adding the buttons to the subview, the NSLog shows that each button has a frame (0,0,0,0) which differs from when I set the frame in the for loop.
2015-10-15 12:25:17.787 kyss[1018:316548] tapped on tags view. Number of subviews = 2. Subviews: (
"<UIButton: 0x15f732330; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x15f72eb60>>",
"<UIButton: 0x15f6d10e0; frame = (0 0; 0 0); opaque = NO; tag = 1; layer = <CALayer: 0x15f6b3790>>"
)

Let's take a look at the code...
for (int i = 0; i<[tags count]; i++) {
NSLog(#"adding tags");
NSMutableDictionary *propertiesdict = [[NSMutableDictionary alloc] init];
propertiesdict = [[tags objectAtIndex:i] mutableCopy];
You create a new dictionary and immediately overwrite the reference with an item from the tags array.
float x = [[dict objectForKey:#"x"] floatValue];
float y = [[dict objectForKey:#"y"] floatValue];
float width = [[dict objectForKey:#"width"] floatValue];
float height = [[dict objectForKey:#"height"] floatValue];
You reference dict, which isn't defined in the code you posted. It's safe to assume that it's not the same as propertiesdict, so you're getting nil references, thus the value 0 for each assignment.
NSString *title = [dict objectForKey:#"text"];
Again with the dict.
UIButton *button = [[UIButton alloc] init];
[button setFrame:CGRectMake(x, y, width, height)];
[button setTitle:title forState:UIControlStateNormal];
button.layer.cornerRadius = 2.5;
//button.alpha = 0.9;
[button.titleLabel setFont:[UIFont systemFontOfSize:13]];
[button setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
button.tag = i;
[button addTarget:self action:#selector(tappedOnTag:) forControlEvents:UIControlEventTouchUpInside];
[tagsView addSubview:button];
}
The rest of the code is ok.
Anyway, your problem is referencing the wrong dictionary. Did you not notice that the title is wrong too?

Related

UIButton is not setting text

I seem to have a problem in my Objective C iOS app where I am creating multiple buttons depending on the amount of objects in an array. I know Swift, so I replicated the logic into Swift, and it worked. Yet in Objective C, I am unable to see the text of the button (after I remove the for loop) or create multiple buttons. For example, I have an array full of three names. I would like to create a button for each name with the title set to the corresponding name. So far, I have this:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *ages = [[NSMutableArray alloc] init];
for (int i = 0; i > 10; i++) {
[ages addObject:[NSString stringWithFormat:#"%i", i]];
}
UIScrollView *scrollView= [[UIScrollView alloc]initWithFrame:self.view.frame];
scrollView.delegate= self;
self.automaticallyAdjustsScrollViewInsets= NO;
scrollView.backgroundColor= [UIColor clearColor];
scrollView.scrollEnabled= YES;
scrollView.userInteractionEnabled= YES;
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];
CGFloat xValue = 0;
for(int x=0; x > ages.count; x++){
UIButton *button= [[UIButton alloc] initWithFrame:CGRectMake(xValue ,0 , 172 ,65)];
UIColor *buttonOutline = [[UIColor redColor] CGColor];
button.layer.borderColor = [buttonOutline CGColor];
button.layer.backgroundColor = [[UIColor clearColor] CGColor];
button.layer.borderWidth = 1.0;
button.layer.cornerRadius = 6.0;
[button.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size:13.0]];
button.titleLabel.text = [ages objectAtIndex:x];
[button addTarget:self action:#selector(test:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
NSLog(#"Button Added");
xValue = button.frame.size.width + 40;
}
scrollView.contentSize = CGSizeMake(xValue, 65);
[self.view addSubview:scrollView];
}
- (void)test:(UIButton*)sender{
NSLog(#"Clicked %#", sender.titleLabel.text);
}
#end
If anyone sees anything wrong with this code, please point it out!
Thanks,
Arnav K.
I found four problems (there may be others) that stop this working correctly:
1) The for loop bound when setting up the ages array is incorrect.
2) The for loop bound when creating the buttons is incorrect.
3) You are setting the buttonOutline colour incorrectly.
4) xValue is being updated incorrectly.
Here is the viewDidLoad method after the changes have been made:
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *ages = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) { // UPDATED
[ages addObject:[NSString stringWithFormat:#"%i", i]];
}
UIScrollView *scrollView= [[UIScrollView alloc]initWithFrame:self.view.frame];
scrollView.delegate= self;
self.automaticallyAdjustsScrollViewInsets= NO;
scrollView.backgroundColor= [UIColor clearColor];
scrollView.scrollEnabled= YES;
scrollView.userInteractionEnabled= YES;
[scrollView setShowsHorizontalScrollIndicator:NO];
[scrollView setShowsVerticalScrollIndicator:NO];
CGFloat xValue = 0;
for(int x=0; x < ages.count; x++){ // UPDATED
UIButton *button= [[UIButton alloc] initWithFrame:CGRectMake(xValue ,0 , 172 ,65)];
UIColor *buttonOutline = [UIColor redColor]; // UPDATED
button.layer.borderColor = [buttonOutline CGColor];
button.layer.backgroundColor = [[UIColor clearColor] CGColor];
button.layer.borderWidth = 1.0;
button.layer.cornerRadius = 6.0;
[button.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size:13.0]];
button.titleLabel.text = [ages objectAtIndex:x];
[button addTarget:self action:#selector(test:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
NSLog(#"Button Added");
xValue += button.frame.size.width + 40; // UPDATED
}
scrollView.contentSize = CGSizeMake(xValue, 65);
[self.view addSubview:scrollView];
}
I have marked the four lines I changed with a UPDATED comment so you can compare them to the original.
EDIT
To change the text and text colour use the following:
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setTitle:[ages objectAtIndex:x] forState:UIControlStateNormal];
and remove this:
button.titleLabel.text = [ages objectAtIndex:x];
You need to do this because you can set different text for the different states of the button and this is all handled automatically for you.

How to remove already created path using CGMutablePathRef?

I am plotting line according bottom selected dots.First Showing start from 0 and after that it showing according to selected dots But line chart is showing previous drawn line.
Here I am using SHLineGrapgView. Here is code :
- (void)drawPlot:(SHPlot *)plot {
NSDictionary *theme = plot.plotThemeAttributes;
//
CAShapeLayer *backgroundLayer = [CAShapeLayer layer];
backgroundLayer.frame = self.bounds;
backgroundLayer.fillColor = [UIColor clearColor].CGColor;
backgroundLayer.backgroundColor = [UIColor clearColor].CGColor;
[backgroundLayer setStrokeColor:[UIColor clearColor].CGColor];
[backgroundLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef backgroundPath= CGPathCreateMutable();
//
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.frame = self.bounds;
circleLayer.fillColor = [UIColor redColor].CGColor;
circleLayer.backgroundColor = [UIColor clearColor].CGColor;
[circleLayer setStrokeColor:((UIColor *)theme[kPlotPointFillColorKey]).CGColor];
[circleLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef circlePath = CGPathCreateMutable();
//
CAShapeLayer *graphLayer = [CAShapeLayer layer];
graphLayer.frame = self.bounds;
graphLayer.fillColor = [UIColor clearColor].CGColor;
graphLayer.backgroundColor = [UIColor clearColor].CGColor;
[graphLayer setStrokeColor:((UIColor *)theme[kPlotStrokeColorKey]).CGColor];
[graphLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef graphPath = CGPathCreateMutable();
double yRange = [_yAxisRange doubleValue]; // this value will be in dollars
double yIntervalValue = yRange / INTERVAL_COUNT;
//logic to fill the graph path, ciricle path, background path.
NSLog(#"plottingValues Dictionary %#",plot.plottingValues);
[plot.plottingValues enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = (NSDictionary *)obj;
NSLog(#"Plotting Dictionary %#",dic);
__block NSNumber *_key = nil;
__block NSNumber *_value = nil;
[dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
_key = (NSNumber *)key;
_value = (NSNumber *)obj;
}];
int xIndex = [self getIndexForValue:_key forPlot:plot];
//x value
double height = self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE;
double y = height - ((height / ([_yAxisRange doubleValue] + yIntervalValue)) * [_value doubleValue]);
(plot.xPoints[xIndex]).x = ceil((plot.xPoints[xIndex]).x);
(plot.xPoints[xIndex]).y = ceil(y);
}];
//move to initial point for path and background.
CGPathMoveToPoint(graphPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
CGPathMoveToPoint(backgroundPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
int count = (int)_xAxisValues.count;
for(int i=0; i< count; i++)
{
CGPathRef path=CGPathCreateCopy(graphPath);
CGPoint point = plot.xPoints[i];
// CGContextRef ref=CGContextCopyPath(<#CGContextRef _Nullable c#>)
// CGContextClip
CGPathAddLineToPoint(graphPath, NULL, point.x, point.y);
CGPathAddLineToPoint(backgroundPath, NULL, point.x, point.y);
CGFloat dotsSize = [_themeAttributes[kDotSizeKey] floatValue];
CGPathAddEllipseInRect(circlePath, NULL, CGRectMake(point.x - dotsSize/2.0f, point.y - dotsSize/2.0f, dotsSize, dotsSize));
}
//move to initial point for path and background.
CGPathAddLineToPoint(NULL, NULL, _leftMarginToLeave + PLOT_WIDTH, plot.xPoints[count -1].y);
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave + PLOT_WIDTH, plot.xPoints[count - 1].y);
//additional points for background.
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave + PLOT_WIDTH, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathCloseSubpath(backgroundPath);
backgroundLayer.path = backgroundPath;
graphLayer.path = graphPath;
circleLayer.path = circlePath;
//animation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"strokeEnd"];
animation.duration = 1;
animation.fromValue = #(0.0);
animation.toValue = #(1.0);
[graphLayer addAnimation:animation forKey:#"strokeEnd"];
backgroundLayer.zPosition = 0;
graphLayer.zPosition = 1;
circleLayer.zPosition = 2;
[self.layer addSublayer:graphLayer];
[self.layer addSublayer:circleLayer];
[self.layer addSublayer:backgroundLayer];
NSUInteger count2 = _xAxisValues.count;
for(int i=0; i< count2; i++){
CGPoint point = plot.xPoints[i];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor clearColor];
btn.tag = i;
btn.frame = CGRectMake(point.x, point.y - 20, 40, 40);
[btn addTarget:self action:#selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
objc_setAssociatedObject(btn, kAssociatedPlotObject, plot, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:btn];
}
}

Create Grid of UIVews in NSArray

What I am trying to do is align views in a grid that are in an array. I have created the views and the array.
for (int i = 0; i < [directoryContents count]; i++){
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,120)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 100, 100);
button.accessibilityIdentifier = [directoryContents objectAtIndex:i];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 100, 20)];
label.textAlignment = NSTextAlignmentCenter;
label.text = [directoryContents objectAtIndex:i];
[containerView addSubview:button];
[containerView addSubview:label];
[self.view addSubview:containerView];
[_containerViewArray addObject:containerView];
}
[self layoutViews:_containerViewArray inView:self.view];
What I have working is aligning them next to each other the problem I am having is I need to have them wrap down instead of going off the edge. What I am doing to algin them is this
- (void)layoutViews:(NSArray *)views inView:(UIView *)contentView
{
NSInteger overallWidth = 0;
for ( UIView *view in views ) {
overallWidth += view.frame.size.width;
}
CGSize contentSize = contentView.frame.size;
CGFloat startOffset = (contentSize.height - overallWidth)/2.0;
CGFloat offset = startOffset;
for ( UIView *view in views ) {
CGRect frame = view.frame;
frame.origin.x = offset;
view.frame = frame;
offset += view.frame.size.width;
}
}
If we assumed that we have an array of sections (your views) and you need to layout 3 item per row the view has size 98*98 and spacing 6.5px horizontally and 8px Vertically
for (int i = 0; i< [sectionsArray count]; i++) {
int row = (int)i/3;
int col = i%3;
float x = 6.5 + (104.5*col);
float y = 8 + (106*row);
UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(x, y, 98, 98)];
sectionView.backgroundColor = [UIColor clearColor];
//button
UIButton *sectionButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[sectionButton setTintColor:[UIColor grayColor]];
sectionButton.frame = CGRectMake(0, 0, 98, 98);
sectionButton.tag = i+100;
[sectionButton addTarget:self action:#selector(showSectionDetail:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:sectionButton];
//adding title
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 75, 98, 20)];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.font=[UIFont fontWithName:#"Helvetica" size:14];
titleLabel.textColor = [UIColor colorWithRed:241.0/255.0 green:124.0/255.0 blue:22.0/255.0 alpha:1.0];
titleLabel.text = [[sectionsArray objectAtIndex:i] objectForKey:#"Title"];
[sectionView addSubview:titleLabel];
[titleLabel release];
[scroll addSubview:sectionView];
[sectionView release];
}
int numberOfRows;
if ([sectionsArray count]/3.0f == 0) {
numberOfRows = [sectionsArray count]/3;
}else{
numberOfRows = [sectionsArray count]/3 +1;
}
scroll setContentSize:CGSizeMake(320, numberOfRows*106);
Here's what I used until the UICollectionView was released, easy to modify to accommodate for how many rows you want in the grid, and the size of the views.
NSUInteger buttonWidth = 100;
NSUInteger buttonHeight = 100;
NSUInteger space = 5;
float scrollContentY = (ceilf((float)imageNames.count / 3.0f) * (buttonHeight + space));
[myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
int row = idx / 3;
int column = idx % 3;
UIView *view = [UIView new];
[view setBackgroundColor:[UIColor redColor]];
view.frame = CGRectMake((buttonWidth + space) * column + space, (buttonHeight + space) * row + space , buttonWidth, buttonHeight);
[view setTag:(NSInteger)idx];
[self.scrollView addSubview:view];
[self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width, scrollContentY)];
}];
Mind you, this might not be advisable if you have a large array to enumerate because this doesn't have any kind of reusable views. It will alloc/init a view for every item in the array.

More than 1 image on a subview not loading

I'm trying to add images over a ScrollView. I have the x and y point in a plist file and they are called by an enum.
enum {
kLogoImage = 1,
kNewLogoImage,
};
#implementation
- (void) _setupStaticViews
{
UIButton *image = [UIButton buttonWithType:UIButtonTypeCustom];
[image setBackgroundImage:[UIImage imageNamed:#"logo.png"] forState:UIControlStateNormal];
[image addTarget:self action:#selector(_addContactButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
image.frame = CGRectMake(0.0 ,0.0, 150.0, 150.0);
image.tag = kLogoImage;
[_mapImageView addSubview:image];
_staticViews = #[image];
UIButton *image2 = [UIButton buttonWithType:UIButtonTypeCustom];
[image2 setBackgroundImage:[UIImage imageNamed:#"Time Bakground.png"] forState:UIControlStateNormal];
[image2 addTarget:self action:#selector(_addContactButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
image2.frame = CGRectMake(0.0 ,0.0, 250.0, 150.0);
image2.tag = kNewLogoImage;
[_mapImageView addSubview:image2];
_staticViews = #[image2];
for ( UIView *view in _staticViews ) {
CGPoint point = [self _basePositionForView:view];
CGRect frame = view.frame;
frame.origin = point;
view.frame = frame;
}
}
If I have only image showing, it works fine. But I need to add more than one and adding the second one causes the first one to be at xy point 0,0, and Image2 isn't visible.
How would I go about adding another image?
- (CGPoint) _basePositionForView:(UIView *)view {
NSString *key = [NSString stringWithFormat:#"%d", view.tag];
NSString *stringValue = [_coordinates objectForKey:key];
NSArray *values = [stringValue componentsSeparatedByString:#":"];
if ( [values count] < 2 ) return CGPointZero;
CGPoint result = CGPointMake([[values objectAtIndex:0] floatValue], [[values objectAtIndex:1] floatValue]);
return result;
}
I noticed that you first make
_staticViews = #[image];
and later
_staticViews = #[image2];
Don't you rather mean to have
_staticViews = #[image, image2];
?
You should iterate and change x accordingly in the frame:
for ( int iterator=0; iterator< [[_staticViews subviews] count]; iterator++){
...
current_image.frame = CGRectMake(YOUR_IMG_WIDTH * iterator ,0.0, YOUR_IMG_WIDTH, 150.0);
...}

Want to Create buttons inside a UITableViewCell and display as seat layout

I am developing an Theatre Ticket booking iOS Application. In that I want to display a seat layout so that an user can select the number of seats he wants. so i planned to display it in row wise and column wise inside a table view. Is that suggested? Or any other solutions are there?? Here is my code for displaying the buttons inside a UIScroll view. How can I move further. Also I need to handle click events for those buttons and get information and handle later. I need some ideas for that too... Please suggest me some samples.
- (Void) someMethod {
int x = 20, y = 15, rows = [rowsArr count];
for (int i = 0; i < [rowsArr count]; i++) {
NSDictionary * rowsDict = [rowsArr objectAtIndex:i];
NSArray * seatsarr = [rowsDict valueForKey:#"Seats"];
if (![[rowsDict valueForKey:#"RowDescription"] isEqualToString:#"Way"])
[self chapterCreationwithtitle:[NSString stringWithFormat:#"%#", [rowsDict valueForKey:#"RowDescription"]]
withChapterTag:tag + i
andXvalue:x andYvalue:y];
y = y + thumb_incrementY;
if (i == rows) { // (main_scroll.frame.size.width-thumb_incrementX))
x = x + thumb_incrementY;
x = 40;
index1++;
rows = (rows + [rowsArr count]);
}
strSeatDes = [[NSMutableArray alloc] init];
int seats = [seatsarr count];
for (int j = 1; j <= [seatsarr count]; j++) {
NSLog(#"index %d", index2);
NSDictionary * seatsDict = (NSDictionary *)[seatsarr objectAtIndex:j - 1];
[strSeatDes addObject:[NSString stringWithFormat:#"%#", [seatsDict valueForKey:#"SeatDescription"]]];
if (![[seatsDict valueForKey:#"isPassage"] boolValue])
[self seatsCreationwithtitle:[NSString stringWithFormat:#"%#", [seatsDict valueForKey:#"SeatDescription"]] withSeatsTag:tag2 + j andXvalue:xx andYvalue:yy];
xx = xx + thumb_incrementX;
NSLog(#"tag seat:%d", tag2 + j);
if (j == seats) {
yy = yy + thumb_incrementY;
xx = 80;
index2++;
tag2 = tag2 + 100;
seats = (seats + [seatsarr count]);
}
}
NSLog(#"%d", [strSeatDes count]);
main_scroll.contentSize = CGSizeMake(([seatsarr count] + 2) * thumb_incrementX + 110, ([rowsArr count] + 2) * thumb_incrementY);
}
} /* someMethod */
- (void) chapterCreationwithtitle:(NSString *)title withChapterTag:(NSInteger)tags andXvalue:(NSInteger)x andYvalue:(NSInteger)y {
chapter_button = [UIButton buttonWithType:UIButtonTypeCustom];
chapter_button.frame = CGRectMake(x, y, button_width, button_height);
chapter_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[chapter_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[chapter_button setTitle:title forState:UIControlStateNormal];
chapter_button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[chapter_button setShowsTouchWhenHighlighted:YES];
[chapter_button setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[chapter_button setBackgroundColor:[UIColor darkGrayColor]];
[chapter_button setTag:tags];
// [chapter_button addTarget:self action:NSSelectorFromString(#"getAction:") forControlEvents:UIControlEventTouchUpInside];
[self.main_scroll addSubview:chapter_button];
}
- (void) seatsCreationwithtitle:(NSString *)title withSeatsTag:(NSInteger)tags andXvalue:(NSInteger)x andYvalue:(NSInteger)y {
seats_button = [UIButton buttonWithType:UIButtonTypeCustom];
seats_button.frame = CGRectMake(x, y, button_width, button_height);
seats_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[seats_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[seats_button setTitle:title forState:UIControlStateNormal];
seats_button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[seats_button setShowsTouchWhenHighlighted:YES];
[seats_button setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[seats_button setBackgroundColor:[UIColor colorWithRed:0.09375 green:0.09765 blue:0.02734 alpha:0.4]];
[seats_button setTag:tags];
[seats_button addTarget:self action:NSSelectorFromString(#"getAction:") forControlEvents:UIControlEventTouchUpInside];
// main_scroll.contentSize = CGSizeMake(x+50, y+50);
[self.main_scroll addSubview:seats_button];
}
If I understand you correctly, you want users to view the seats as they are laid out in the theatre, and to highlight one or more seats in order to book them.
If this was me, I would not use a UITableView. I think in iOS tables are actually more for displaying lists than two dimensional information. However, it can be done - basically you make your own custom cell which is split in to columns. Some code here https://github.com/AlanQuatermain/AQGridView might be useful.
Personally I would think about maybe just having a grid of UIButton controls instead. It depends on how many seats there are, and if they fit on to a single screen.