UISegmentedControl not responding - ios

I'm adding a UISegmentedControl to the foot of a grouped UITableView programmatically. It's showing up fine, but when I tap on any of the options, they don't highlight. What am I doing wrong here? Also, how do I set a default item to be highlighted?
- (void)viewDidLoad
{
[super viewDidLoad];
// set up cacheControl
NSArray* cacheDays = [NSArray arrayWithObjects: #"1", #"2", #"3", #"4", #"5", nil];
self.cacheControl = [[UISegmentedControl alloc] initWithItems:cacheDays];
[self.cacheControl setTintColor:[UIColor blackColor]];
[self.cacheControl addTarget:self action:#selector(cacheSelection:) forControlEvents:UIControlEventValueChanged];
self.cacheControl.frame = CGRectMake(10, 16, self.tbl.frame.size.width-20, 47);
[self.cacheControl setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
}
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
switch (section) {
case 0:{
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, tbl.contentInset.top)];
footerView.backgroundColor = [UIColor clearColor];
return footerView;
}
case 1:{
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, 16)];
footerView.backgroundColor = [UIColor clearColor];
[footerView setClipsToBounds:NO];
[footerView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
[footerView addSubview:self.cacheControl];
return footerView;
}
}
return nil;
}
Screenshot, as requested:

To set a default item, do: [cacheControl setSelectedSegmentIndex:0] with the index that you want selected.

You should implement -tableView:heightForFooterInSection: from the UITableViewDelegate protocol.
This will let the table view adjust the height of the section footer to fit your view and allow it to receive user interactions.

Related

How to Show the Pickerview value in Textfield and hide the pickerView using barbuttonitem?

I am Having 2 Textfields stateText and providerText.If i click the first textfield means,it shows the pickerView.After That i will Select the pickerView Value.Also i have added the toolbar barbuttonitem in that pickerView.Then I have to show the pickerView value in the Textfields and hide the pickerView after selecting the value in the PickerView.Also Pointer should moves to next TextField connectionNoText after getting Values in TextFields.
1.How to hide the PickerView and show the value in TextField?
2.How to show the pickerview in the Bottom of the View irrespective of phone size?
This is my Source Code:
NewConnectionviewController.m
-(void)viewDidLoad
{
[super viewDidLoad];
//ScrollView
self.view.backgroundColor = [UIColor grayColor];
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height + 510.0)];
[self.view addSubview:scrollView];
//statePickerView
_statePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view. frame.size.height, self.view.frame.size.width, 216)];
_statePickerView.delegate = self;
_statePickerView.dataSource = self;
_statePickerView.showsSelectionIndicator = YES;
[_statePickerView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:_statePickerView];
//providerPickerView
_providerPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view. frame.size.height, self.view.frame.size.width, 216)];
_providerPickerView.delegate = self;
_providerPickerView.showsSelectionIndicator = YES;
[_providerPickerView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:_providerPickerView];
//ToolBar
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleBordered target:self action:#selector(hidePickerView:)];
toolBar.items = #[barButtonDone];
barButtonDone.tintColor=[UIColor lightTextColor];
[barButtonDone setEnabled:YES];
[_statePickerView addSubview:toolBar];
//[_providerPickerView addSubview:toolBar];
//GettingView
[self stateView];
[self providerView];
[self connectionNoView];
[self addTestView];
}
-(void)hidePickerView:(UIBarButtonItem *)sender
{
NSLog(#"clicked");
[self.selectState resignFirstResponder];
}
-(void)stateView
{
UIView *stateView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, 80)];
stateView.backgroundColor = [UIColor blueColor];
[scrollView addSubview:stateView];
//stateLabel
UILabel *stateLabel = [[UILabel alloc]initWithFrame:CGRectMake(stateView.frame.origin.x+20,35, 70, 20)];
[stateLabel setText:#"State"];
[stateLabel setTextColor:[UIColor whiteColor]];
[stateView addSubview:stateLabel];
//TextField
NSLog(#"stateViewSize==>>%f",stateView.frame.origin.y);
stateText = [[UITextField alloc]initWithFrame:CGRectMake(stateView.frame.origin.x+110, 30, 150, 40)];
stateText.textColor = [UIColor blackColor];
stateText.backgroundColor = [UIColor clearColor];
[stateText setBorderStyle:UITextBorderStyleRoundedRect];
[stateText setPlaceholder:#"select State"];
[stateText setTag:0];
[stateView addSubview:stateText];
[stateText setDelegate:self];
}
-(void)providerView
{
UIView *providerView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+80, self.view.frame.size.width, 80)];
providerView.backgroundColor = [UIColor orangeColor];
[scrollView addSubview:providerView];
NSLog(#"providerViewsize==>>%f",providerView.frame.origin.y);
//providerLabel
UILabel *providerLabel = [[UILabel alloc]initWithFrame:CGRectMake(providerView.frame.origin.x+20, 35, 70, 20)];
[providerLabel setText:#"Provider"];
[providerLabel setTextColor:[UIColor whiteColor]];
[providerView addSubview:providerLabel];
//TextField
providerText = [[UITextField alloc]initWithFrame:CGRectMake(providerView.frame.origin.x+110,30, 150, 40)];
providerText.textColor = [UIColor blackColor];
[providerText setPlaceholder:#"select Provider"];
providerText.backgroundColor = [UIColor clearColor];
[providerText setTag:1];
[providerText setBorderStyle:UITextBorderStyleRoundedRect];
[providerView addSubview:providerText];
[providerText setDelegate:self];
}
-(void)connectionNoView
{
UIView *connectionNoView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+160, self.view.frame.size.width, 150)];
connectionNoView.backgroundColor = [UIColor greenColor];
[scrollView addSubview:connectionNoView];
NSLog(#"connectionNoViewsize==>>%f",connectionNoView.frame.origin.y);
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView
if (textField.tag ==0)
{
//stateText.inputView = _statePickerView;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_statePickerView.frame = CGRectMake(0, self.view.frame.size.height-216,self.view.frame.size.width, 216);
}
completion:^(BOOL finished){
}];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#""
message:#"Please select state first."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;//Or return whatever as you intend
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
if([thePickerView isEqual:_statePickerView])
{
return [STATE_ARRAY count];
}
else
{
return [PROVIDER_ARRAY count];
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if([thePickerView isEqual:_statePickerView])
{
return [STATE_ARRAY objectAtIndex:row];
}
else
{
return [PROVIDER_ARRAY objectAtIndex:row];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *firstPickerViewValue;
NSString *secondPickerViewValue;
if ([pickerView isEqual:_statePickerView])
{
firstPickerViewValue = [STATE_ARRAY objectAtIndex:row];
[_providerPickerView selectRow:row inComponent:0 animated:YES];
secondPickerViewValue = [PROVIDER_ARRAY objectAtIndex:row];
[_providerPickerView reloadAllComponents];
[stateText setText:[NSString stringWithFormat:#"%#",firstPickerViewValue]];
[providerText setText:[NSString stringWithFormat:#"%#",secondPickerViewValue]];
}
I have read through the code and to be honest Im pretty confused by your approach as I tend to avoid magic numbers when laying out the UI. Anyway I think both your questions can be solved by assigning the inputView of your slate textField and assigning the inputAccessoryView to the toolbar you created in the code.
So for example,
stateText.inputView = _statePickerView
Well that is Swift so you would have
[stateText setInputView:_statePickerView];
Then you set the Accessory View so
[stateText setInputAccessoryView: toolBar];
Although toolbar is only in scope inside your viewDidLoad method so you should fix that. This should be enough to get you back on the right path. To dismiss the pickerView just resignFirstResponder of the selected textField inside your hidePickerView method.
Note that your textfields are also confined to the methods they are created in so you should fix that too.
Finally i Found a Solution.PickerView itself a ViewController so we can't hide the pickerView.Alternative solution is,
1.Create the SubView with Height 260 and add that View to the Self.View.
(set Y Value as Self.View.Frame.Size.height).
2.Add the PickerView(default Height - 216) and ToolBar(default Height - 44) to that SubView.
3.In BarButtonItem action Move that view to the bottom.(ex.Set Frame like this) CGRectMake(0,Self.View.Frame.Size.Height,Self.View.Frame.Size.Width,216)

Add loading footer on UITableView

I have a UITableView. When I scroll to the bottom it loads more data. How can I add a loading animation to the footer of the table when it´s scrolled to the bottom?
You can use MNMBottomPullToRefreshManager file to load more data. First you have to initialize it in viewDidLoad as
pullToRefreshManager_ = [[MNMBottomPullToRefreshManager alloc] initWithPullToRefreshViewHeight:60.0f tableView:table withClient:self];
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[pullToRefreshManager_ tableViewScrolled];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate
{
[pullToRefreshManager_ tableViewReleased];
}
- (void)bottomPullToRefreshTriggered:(MNMBottomPullToRefreshManager *)manager
{
//method to get more data
// [self CallWebServiceToLoadMorePAYMENTS];
}
}
After reloading your tableView call:
[pullToRefreshManager_ tableViewReloadFinished];
Try this
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = [[[UIView alloc] init]autorelease];
[headerView setBackgroundColor:[UIColor clearColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Load More" forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);
[headerView addSubview:button];
return headerView;
}
Use this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(array.count>1){
if(indexPath.row == array.count-1){
[self setupTableViewFooter];
}
}
}
- (void)setupTableViewFooter
{
// set up label
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
footerView.backgroundColor = [UIColor clearColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:Font_MuseoSans size:14];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.textColor = [UIColor darkGrayColor];
label.text = #"Loading";
self.footerLabel = label;
CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size];
[footerView addSubview:self.footerLabel];
// set up activity indicator
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicatorView.hidesWhenStopped = YES;
activityIndicatorView.color = [UIColor blackColor];
self.activityIndicator = activityIndicatorView;
[self.activityIndicator startAnimating];
[footerView addSubview:self.activityIndicator];
CGRect footerFrame = footerView.frame;
label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2
, (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height);
self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2
, activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
self.tableView.tableFooterView = footerView;
}

unwanted white space "under" tableView subview when tableView scrolled to its content limits

I have a UITableViewCell as a subview in a custom view controller. It works great except that when it scrolls to its top or bottom of its contentSize limit, it "keeps going" and leaves some white space exposed behind it. This is particularly irritating because I do have a UIView covering the entire screen behind the tableView, and that view is set to a non-white color. I also added a subview exactly underlaying the tableview with the same background color, again attempting to block the white. I also set the UIApplication Window background color to a non white color. None of this worked.
I would have thought that even if my TableView bounces around its origin frame, the "exposed" view should match the underlying view rather than be white. How can I fix my tableView so that it retains all its scroll properties but doesn't reveal white when it bounces around at the end of a scroll?
Here is a screen shot of the effect. The white appears the tableViewHeader and below a UISCrollView that occupies the top of the screen. This appears when I scroll the tableView all the way to one extreme. The white space appears at the bottom rather than the top of the tableView if I scroll all the way to the other end.
Here's the relevant code, quite vanilla I think:
#interface JudgeViewController () <UITextFieldDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIGestureRecognizerDelegate, UITableViewDataSource, UITableViewDelegate, UIViewControllerRestoration, UIScrollViewDelegate>
#property (nonatomic) UITableView *tableView;
#end
functions to set tableViewCells
#pragma mark - tableview appearance and actions
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
StatsViewController *svc = [[StatsViewController alloc] init];
svc.user = self.object.answerUser[indexPath.row];
svc.fromJudge = YES;
[self.navigationController pushViewController:svc animated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.object.answerArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if(cell ==nil)
{
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode: UILineBreakModeWordWrap];
[label setMinimumFontSize:SMALL_FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:SMALL_FONT_SIZE]];
[label setTag:1];
// [[label layer] setBorderWidth:2.0f];
[[cell contentView] addSubview:label];
}
CGFloat width = [[UIScreen mainScreen] bounds].size.width;
CGFloat height = [[UIScreen mainScreen] bounds].size.height;
NSString *text = self.object.answerArray[indexPath.row];
CGSize constraint = CGSizeMake(.8*CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN)*2, 200000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:SMALL_FONT_SIZE] constrainedToSize:constraint];
if(!label)
label = (UILabel *)[cell viewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, .8*CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN)*2, MAX(size.height, 44.0f))];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(.85*width, label.frame.size.height/2-2*CELL_CONTENT_MARGIN, .12*width, 20);
[button1 setTitle:#"UP" forState:UIControlStateNormal];
button1.titleLabel.font =[UIFont systemFontOfSize:SMALLEST_FONT_SIZE];
[button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button1 addTarget:self action:#selector(upVoteA:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button1];
[cell.contentView bringSubviewToFront:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(.85*width, label.frame.size.height/2+2*CELL_CONTENT_MARGIN, .12*width, 20);
[button2 setTitle:#"DOWN" forState:UIControlStateNormal];
button2.titleLabel.font =[UIFont systemFontOfSize:SMALLEST_FONT_SIZE];
[button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button2 addTarget:self action:#selector(downVoteA:) forControlEvents:UIControlEventTouchUpInside];
CGFloat moduloResult = indexPath.row % 2;
if(moduloResult>0)
{
cell.backgroundColor = [UIColor colorWithRed:1 green:0.647 blue:0 alpha:.6];
}
else
{
cell.backgroundColor = [UIColor colorWithRed:1 green:0.647 blue:0 alpha:.4];
}
cell.opaque = NO;
cell.alpha = 0.2;
[cell.contentView addSubview:button2];
[cell.contentView bringSubviewToFront:button2];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(void)keyboardToJudge
{
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row < [self.object.answerArray count])
{
NSString *text = self.object.answerArray[indexPath.row];
CGSize constraint = CGSizeMake(.8*CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN)*2, 200000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE-2.0f] constrainedToSize:constraint];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN)*2;
}
else
{
return 200.0f;
}
}
functions setting out layout:
-(void)viewDidLoad
{
...among other things setting up top scroll view (top part of view with gray background and orange text)...
if(self.navigationController.navigationBar.frame.size.height>0)
{
self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 5, width, height*SCROLL_VIEW_OFFSET)];
}
else
{
self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, statusBarHeight+5, width, height*SCROLL_VIEW_OFFSET)];
}
self.scroll.backgroundColor = BACKGROUND_COLOR;
self.scroll.contentSize =CGSizeMake(width, .5*height);
self.scroll.delegate = self;
self.scroll.contentInset = UIEdgeInsetsMake(30, 0, 30, 0);
[self.scroll setShowsHorizontalScrollIndicator:NO];
...adding buttons to self.scroll...
[self.view addSubview:self.scroll];
....
self.tableView = [[UITableView alloc] initWithFrame:frame];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _width, _height*.1)];
self.tableView.tableFooterView.backgroundColor = BACKGROUND_COLOR;
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _width, _height*.1)];
self.tableView.tableHeaderView.backgroundColor = BACKGROUND_COLOR;
....tableView hidden state is changed to yes in another function if row count is zero but not usually...
self.tableView.hidden = NO;
[self.view addSubview:self.tableView];
...
}
Finally, I also call :
[self.tableView reloadData];
after reloading data from a webserver and depending on the results either set the tableView to hidden or not (not hidden if there are results to display). That should be every line of code that touches the tableView subview.
Add to your viewDidLoad
[self.tableView setBackgroundColor:BACKGROUND_COLOR];
Set the background color of your tableView and you'll be fine
Change this line:
self.scroll.contentInset = UIEdgeInsetsMake(30, 0, 30, 0);
To this:
self.scroll.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
You are adding a footer to your tableview with that line. The following image is from the IOS dev Library
Set the table view estimate to 0 (Uncheck Automatic) in the size inspector

Create custom UITableView header with white text and red background

I have a UITableView that needs a simple custom header that has a background color and a white label. This is my code:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *titleString = #"Title";
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 45)];
[headerView setBackgroundColor:[UIColor redColor]];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:headerView.frame];
headerLabel.text = titleString;
headerLabel.textColor = [UIColor whiteColor];
[headerView addSubview:headerLabel];
return headerView;
}
I can change the background color without any problem, but for some reason the label always shows gray text color. I'm also using a custom category to change all fonts to a custom one that looks like this (I don't think this is the problem but anyway..):
- (void)awakeFromNib
{
[super awakeFromNib];
[self setFont:[UIFont fontWithName:#"MyFont" size:self.font.pointSize]];
}
-(id)initWithFrame:(CGRect)frame
{
id result = [super initWithFrame:frame];
if (result) {
[self setFont:[UIFont fontWithName:#"MyFont" size:self.font.pointSize]];
}
return result;
}
Any idea why could this be happening?

Setting custom header view in UITableView

I am trying to add a custom view to the header of each of my UITableView's sections. I am using this delegate method to return the desired view. It is working partly as it causes the cell sections to be spread out as if there was a header there, however neither the text or UIButton actually appear. I know this method is being called as I places an NSLog in the method to see if it was. Am I making some kind of silly mistake, or is this not the right way of doing this?
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 44.0)];
customView.backgroundColor = [UIColor clearColor];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 44.0)];
headerLabel.textColor = [UIColor darkGrayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// add button to right corner of section
return customView;
switch (section) {
case 0:
headerLabel.text = #"Team Name";
break;
case 1:
headerLabel.text = #"Captain";
break;
case 2:
headerLabel.text = #"Wicket Keeper";
break;
case 3:
headerLabel.text = #"Batting Order";
headerButton.center = CGPointMake( 160.0, 22.0);
headerButton.backgroundColor = [UIColor blueColor];
headerButton.tag = section;
[headerButton addTarget:self action:#selector(enableCellReordering:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:headerButton];
break;
default:
break;
}
[customView addSubview:headerLabel];
return customView;
}
Found it, you return customView; before the switch statement.
You return your customview twice , one before switch statement one after switch statement twice just need to remove return customView; before switch (section)
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string =[list objectAtIndex:section];
/* Section header is in 0th index... */
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
return view;
}
What about the custom header origin.x and origin.y ?
when I set them non-zero, but it's still next to the ledt edge.

Resources