How to remove separator in tableView? - iphone

I make one tableview in which I add button type cell using custom cell. Looks good but when there is less cell in tableview at that time separator looks very bad. In design so there is any solution than tell me.
I try to remove separator from design but it does not work.
- (void)viewDidLoad {
self.navigationItem.title = #"My List";
self.tblView.separatorStyle = UITableViewCellSeparatorStyleNone;
[[self tableView] setRowHeight:70];
[[self tableView] setBackgroundColor:[UIColor blackColor]];
Helath_ndroidAppDelegate *appDeleg = (Helath_ndroidAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *temp1 =[[NSMutableArray alloc] init];
appDeleg.recipCategoryFromDatabase = temp1;
[temp1 release];
dataBase *objData = [[[dataBase alloc] init] autorelease];
[objData selectrecepFromDatabase];
[[self tableView] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];
[super viewDidLoad];
}

Have you tried to remove separator programmatically?
I use this code with my custom cells...
In your viewDidLoad method add this line of code if you are using an UITableViewController:self.yourTableViewHere.separatorStyle = UITableViewCellSeparatorStyleNone;

Related

Delegate Methods Not Firing on Search Results Table

All,
I have a UITableView w/detail, with a Search bar, created from code. Works fine on selected items except it doesn't work when an item is clicked from the search results; no delegate methods fire. Never seen this type of behavior before so I don't know where the issue lies.
I get the same behavior with standard table cells as well as custom table cells.
Appreciate any guidance on this and thanks.
Just Hangs Here
//ViewController.h
#interface SongsViewController : UITableViewController <UISearchBarDelegate,UISearchDisplayDelegate>
{
NSMutableArray *searchData;
UISearchBar *searchBar;
UISearchDisplayController *searchDisplayController;
UITableViewCell *customSongCell;
}
//ViewController.m
-(void)viewDidLoad
{
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 88)];
[searchBar setShowsScopeBar:YES];
[searchBar setScopeButtonTitles:[[NSArray alloc] initWithObjects:#"Title",#"Style", nil]];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableView.tableHeaderView = searchBar;
//Load custom table cell
UINib *songCellNib = [UINib nibWithNibName:#"SongItem" bundle:nil];
//Register this nib, which contains the cell
[[self tableView] registerNib:songCellNib forCellReuseIdentifier:#"SongItemCell"];
// create a filtered list that will contain products for the search results table.
SongStore *ps = [SongStore defaultStore];
NSArray *songObjects = [ps allSongs];
self.filteredListContent = [NSMutableArray arrayWithCapacity: [songObjects count]];
self.masterSongArr = [[NSMutableArray alloc] initWithArray:[ps allSongs]];
[self refreshData];
[self.tableView reloadData];
self.tableView.scrollEnabled = YES;
}
I fixed this issue. I forgot to set this searchDisplayController delegates:
[searchDisplayController setSearchResultsDelegate:self];
So make sure you set All of these:
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
[searchDisplayController setSearchResultsDelegate:self];

Update Label in Table View

I have a table view where is showed the name of every element of a database. One field is the price of that element.
I use this UILabel to show the sum of all the prices, and it works perfectly.
- (void)viewWillAppear:(BOOL)animated
{
conto = [[NSNumber alloc] initWithDouble:0];
shoppingListItems = [[NSMutableArray alloc] init];
[super viewWillAppear:animated];
[self loadDataFromDb];
[self sortListArray];
[self.tableView reloadData];
if ([conto intValue] < 0) {
walletLabel.textColor = [UIColor redColor];
} else { walletLabel.textColor = [UIColor greenColor]; }
walletLabel.text = [[NSString alloc] initWithFormat: #"Saldo: %#€", [conto stringValue]];
}
"conto" variable is calculate inside "loadDataFromDB" method.
I would like to update it every time I delete a row from the table.
Any suggestion?
Easy. Just call your update routine in your tableView:commitEditingStyle:forRowAtIndexPath: method.

subView in DetailViewController?

I have a main table view and a detail view. when i click cell detail view should show the details of that item. now what i wanna do is to create subview and put that subview in detailView instead of creating a detailview for every cell. it ll solve my some other problems. Code looks like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *nextController = [[DetailViewController alloc] init];
int storyIndex = [indexPath indexAtPosition:[indexPath length] -1];
[nextController initWithObjectAtIndex:storyIndex inArray:stories];
NSString *storyTitle = [[stories objectAtIndex:storyIndex] objectForKey:#"title"];
nextController.title = #"Details";
UIBarButtonItem *tempButtonItem = [[[UIBarButtonItem alloc] init] autorelease];
tempButtonItem.title = #"Tillbaka";
self.navigationItem.backBarButtonItem = tempButtonItem ;
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
now how can i create a subview with a label and change text of that label to storyTitle.
thanx in advance.
how can i create a subview with a label and change text of that label to storyTitle
Given a parent view, you don't need to create a new subview just to add a label to the parent. But, assuming you really do want to add a subview with a label to your parent view, then do this:
...
UIView *parentView;
...
UIView *subView = [[[UIView alloc] initWithFrame:mySubViewFrame] autorelease];
UILabel *lbl = [[[UILabel alloc] initWithFrame:myLabelFrame] autorelease];
lbl.text = storyTitle;
[subView addSubview: lbl];
[parentView addSubview: subView];

Update UIPickerView Number of Rows

I have a UIPickerView that is populated by an NSMutableArray called sectionNamesArray. When an item is added to sectionNamesArray, how do I manually get this delegate to be called?
-- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return ([sectionNamesArray count] + 1);
}
The problem is that I add this pickerView to the center of a navBar in the titleView. If I try to nil the UIPickerView and reallocate it in order to hopefully get the delegate called again, the PickerView shows up on the left side of the navbar, instead of the center. I am guessing maybe the interface builder settings got it in the center...?
Here's the code for that:
-(void) setupPickerView{
myPickerView = nil;
myPickerView = [[UIPickerView alloc] init];
myPickerView.backgroundColor = [UIColor clearColor];
myPickerView.delegate = self;
myPickerView.dataSource = self;
myPickerView.showsSelectionIndicator = YES;
[self.navigationController.navigationBar setBackgroundView:myPickerView];
CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero];
UIView *pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(-40.0, -43.0, pickerSize.width, pickerSize.height)];
pickerTransformView.transform = CGAffineTransformMakeScale(.55f, .55f);
[pickerTransformView addSubview:myPickerView];
[self.navigationController.navigationBar setBackgroundView:pickerTransformView];
}
When you add something to your array can't you use [UIPickerView reloadAllComponents] or - (void)reloadComponent:(NSInteger)component?
That will most likely query your delegate and call everything necessary to check your array and reload the view.

UITextField resignFirstResponder not working?

I've double checked all the connections in the nib file. My code -
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"iphone_bg_login.png"]];
self.title = #"Login screen";
loginTxt = [[UITextField alloc] init];
pwdText = [[UITextField alloc] init];
loginFailedTxt = [[UILabel alloc] init];
loginBtn = [[UIButton alloc] init];
navAppDelegate = (NavAppDelegate *)[[UIApplication sharedApplication] delegate];
navAppDelegate.navController.navigationBarHidden = YES;
//NSArray *subVs = (NSArray *) [self.view subviews];
[super viewDidLoad];
}
I've used a subclass of UIView (UIControl) and added all the UI elements to it in the Interface builder.The UIControl's touchDown method is connected to backgroundTap method.
-(IBAction) backgroundTap:(id) sender {
[loginTxt resignFirstResponder];
[pwdText resignFirstResponder];
//[[UIApplication sharedApplication] becomeFirstResponder];
//[sender resignFirstResponder];
}
So the keyboard isn't removed like it's supposed to. Not sure why.
Thanks for the help!
Teja.
DyingCactus has pointed to your error. You're replacing the NIB-version of the control with a completely different control, losing your pointer to the one in the NIB. When you call resignFirstResponder, you're calling it on your duplicate object, not the one that's actually on the screen. Get rid of the alloc and init calls for things wired in the NIB.