简体   繁体   中英

Two title bars on UIViewController (subview of UITableViewController)

So I have a table view controller that shows pictures then when you select a cell it opens a UIViewController with an image view and a navigation bar with buttons to go back or to save the image. The problem is that I'm getting a second title bar. I can't seem to remove it, I can't change the text, and to be honest I can't seem to find where it's coming from. When I select it it selects the navigation bar but if I delete or hide the navigation bar it hides the bar with the buttons and this "Title" bar stays.

Here's what it looks like running in the simulator:

titleBar问题

Any ideas on how I can get rid of this thing or at least change it's title? The only thing that seems to change it is when I load a very small image it will expand to fill the remaining view space like so:

largeTitleBar

I've deleted the UIImageView and even the view in the nib and it's still there. I've even deleted the nib itself and nothing changes. I can only guess that the superview is loading it somehow but I can't find anything in there that could cause it. If it were coming from the cell method it would have the title of the image and not just "title."

Here's the code from the Superview (which is a table view controller) that initializes the screen with the problem:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *title = [completePicturesList objectAtIndex:row];
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *imagePath = [NSString stringWithFormat:@"%@/%@", docDirectory, title];

UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];

GCDetailViewController *childController = [[GCDetailViewController alloc] init];
childController.mainImage = image;
[self.navigationController pushViewController:childController animated:YES];

}

and here's the viewWillAppear of the UIViewController that's showing the duplicate:

- (void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated];

mainImageDisplay.image = mainImage;

UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Save"
                                                               style:UIBarButtonItemStyleBordered target:self action:@selector(saveImageToPhotoAlbum)];
self.navigationItem.rightBarButtonItem = editButton;
NSString *titleText = [NSString stringWithFormat:@"Image Review"];
self.title = titleText;

The only other methods in this class are for saving the photo. Also, no nib is assigned to this either so it's not there. As for self.title, well if I change that it changes the text that says "Image Review" NOT the "title" below it. If I try to hide the navigation bar it hides the image review bar and the title bar stays.

Just for fun here's the cellForRow method to see if maybe it's something in there:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @"newCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

NSUInteger row = [indexPath row];
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *cellTitle = [completePicturesList objectAtIndex:row];
NSString *imagePath = [NSString stringWithFormat:@"%@/%@", docDirectory, cellTitle];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];

cell.textLabel.text = cellTitle;
cell.imageView.image = image;

return cell;

}

Please excuse me if it's not OK to answer my own question but I did find the solution.

The title bar came from an old nib. I made it in the storyboard, added the bar, then changed my mind on how I wanted to approach it and deleted it.

For whatever reason when I was reloading the app, both on the simulator and on my phone, it wasn't overwriting the old nib that originally caused this problem (even though it was deleted from xCode). I simply deleted the app from the phone and simulator and reloaded it and the title bar was gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM