My iOS 7.1 App has a strange Bug. See Pic below. It's happen when i try to pushing the Alarm-ViewController on UITableView:didSelectRowAtIndexPath Event. Any Ideas how to fix that ?
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Alarm *alarm = _settings.sharedSettings[indexPath.row];
AlarmViewController *alarmViewController = [[AlarmViewController alloc] initWithAlarm:alarm];
alarmViewController.title = NSLocalizedString(#"TITLE", nil);
[self.navigationController pushViewController:alarmViewController animated:YES];
}
Simple Solution.
Just set the Background-Color of the UIView.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
view.backgroundColor = [UIColor whiteColor];
//add other Controls to view
self.view = view;
Related
The statement:
[tableView setBackgroundColor:[UIColor clearColor]];
has no effect only on iPad especially with iOS8 with my existing App only. Just for a shake of test I have created a new Test App just to pin point the problem but it works. I have created a UIViewController class like this:
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view setBackgroundColor:[UIColor purpleColor]];
UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 300, 300) style:UITableViewStylePlain];
[aTableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:aTableView];
}
#end
and push ist with the following statement:
[self.navigationController pushViewController:[TestViewController new] animated:YES];
Pushing from the new Test App results like this (as I want):
but from my existing App (the real App where I have to implement) result like this:
Clearing the background color works perfectly under iOS7 iPhone and iPad even with iOS 8 iPhone. I have tried to find UIAppearance Proxy implementation that can influence the appearance but there isn't any.
I have already tried several SO proposals including setting the backgroundView to nil and they haven't helped.
Why it is working with new Test App and why it is not working with my Existing App? Anything to do with UINavigationController?
NB: Please don't mark as a duplicate because here the question is totally or slightly different than the existing ones.
This is cell's color. So you have to change your cell's color. For more info see
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
}
UIView *bgView = [[UIView alloc] initWithFrame:cell.frame];
bgView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bgView;
Try the above code
I'd like to pop an view with textInput box and button. I can't understand why UITableView works but UIView doesn't.
- (void)viewDidLoad
{
[super viewDidLoad];
self.containerView = [[UITableView alloc] initWithFrame:CGRectMake(20, 100,200,200)];
[[self view]addSubview:self.containerView];
}
Use above code I can saw the view. But if I change to:
- (void)viewDidLoad
{
[super viewDidLoad];
self.containerView = [[UIView alloc] initWithFrame:CGRectMake(20, 100,200,200)];
[[self view]addSubview:self.containerView];
}
I will get nothing, a black screen. Nothing displayed.
Could someone tell me the reason? Thank you very much.
self.containerView = [[UIView alloc] initWithFrame:CGRectMake(20, 100,200,200)];
self.containerView.backgroundColor = [UIColor redColor];
try this code
.
I have an iPad app (XCode5, ARC, Storyboards, iOS 7). This is the problem (placeholder and cursor in middle of UITextField):
This is the code that creates it:
- (IBAction)bSendFeedback:(UIButton *)sender {
// make the popover
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0]; // frame color?
popoverContent.view = popoverView;
//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(450, 500);
// add the UITextfield to the popover
UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 450, 500)];
[tf becomeFirstResponder];
tf.delegate = self;
tf.tag = kSendFeedback;
tf.placeholder = #" Enter your comments here";
tf.backgroundColor = UIColorFromRGB(0xFFFFE0);
tf.returnKeyType = UIReturnKeyDone; // make return key read "Done"
[popoverView addSubview:tf];
// if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:((UIButton *)oSendFeedback).frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
The image is from running under iOS7; it works fine when running under iOS 6.
As you can see, it kind of works but the cursor/placeholder should be at the top of the UITextField... any ideas why it's not there when running under ios&?
It appears that Apple has changed the default vertical alignment of a UITextField to center (UIControlContentVerticalAlignmentCenter) in iOS 7 versus top (UIControlContentVerticalAlignmentTop) in iOS 6 & previous version.
To fix it in all versions, please add this line -
tf.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
This will put the cursor and placeholder text at the top. Good catch !!
I have no clue how can I set grouped style as default to UITableView subclass. My goal is to get grouped TableView (ofc) but by something like that.
TableSubclass *myView = (TableSubclass*)some.other.view
Is this possible? I will be greatful for any advice.
UPDATE
I have ios 6 app with custom UITabBar and custom more section.
My "custom" code
- (void)viewDidLoad
{
[super viewDidLoad];
firstUse=true;
UINavigationController *moreController = self.moreNavigationController;
moreController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.moreNavigationController.delegate = self;
if ([moreController.topViewController.view isKindOfClass:[UITableView class]])
{
UITableView *view = (UITableView *)moreController.topViewController.view;
view = [view initWithFrame:view.frame style:UITableViewStyleGrouped];
UIView* bview = [[UIView alloc] init];
bview.backgroundColor = [UIColor blackColor];
[view setBackgroundView:bview];
moreTableViewDataSource = [[NXMoreTableViewDataSource alloc] initWithDataSource:view.dataSource];
view.dataSource = moreTableViewDataSource;
}
}
It's working great under 6 but under 7 UITableView don't respond but when I remove
[view initWithFrame:view.frame style:UITableViewStyleGrouped];
It respond again but I lose grouped style.
Are you sure that the table view is not yet configured?
from UITableView Class Reference
When you create a UITableView instance you must specify a table style,
and this style cannot be changed
Have a look how to create and configure UITableView.
Generally you use UITableViewController and then in:
- (void)loadView
{
UITableView *tableView =
[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]
style:UITableViewStylePlain];
...
}
So, as the title says, I have an hdmi out on the iPad and an observer registered for screen connections, upon connection the user chooses the res and a view is outputted.
However, if I load a view from a nib, or even from a programatic view controller, the ipad shows a landscape view in portrait (yes, both situations are set to landscape).
I.e.
ExternalViewController *ex = [[ExternalViewController alloc] init];
[externalWindow setRootViewController:ex];
does this:
If I create the view itself programatically. like so:
UIView *test = [[UIView alloc] initWithFrame:[externalScreen applicationFrame]];
[test setBackgroundColor:[UIColor whiteColor]];
UILabel *msgLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 100, 30)];
msgLabel.text = #"External!";
[test addSubview:msgLabel];
It runs like some form of magical dream:
However I want the viewcontroller to load (and work!) so, StackOverflow, I ask you. has anyone come across this before?
EDIT: It does go without saying that common sensical answers do not get a bounty, I am after a fix, not a workaround. With my limited brain, all I can think to do is create a method that creates a view based on it's inputs and adds that as a subview of the external monitor, it is clear that this is a hack solution so a fix is appreciated! Thanks!
EDIT:
-(id)initWithFrame:(CGRect)_rect
{
rect = _rect;
if (self = [super init])
{
externalView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"105.png"]];
externalView.alpha = 0.0;
[externalView setFrame:rect];
[externalView setBackgroundColor:[UIColor yellowColor]];
self.view = [[UIView alloc] initWithFrame:rect];
self.view.backgroundColor = [UIColor whiteColor];
return self;
}
}
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:rect];
self.view.backgroundColor = [UIColor blackColor];
[self.view addSubview:externalView];
}
As requested, this is how I am loading the viewcontroller, initialising with the size of the external screen. Thanks
Just return NO in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation in your UIViewController subclass.
// ugly, don't use this in real code
if ([UIScreen screens].count == 1) return; // just one screen, eww.
// getting the secondary screen
UIScreen *screen = [[UIScreen screens] objectAtIndex:1];
__block UIScreenMode *highestWidthMode = NULL;
[screen.availableModes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIScreenMode *currentModeInLoop = obj;
if (!highestWidthMode || currentModeInLoop.size.width > highestWidthMode.size.width)
highestWidthMode = currentModeInLoop;
}];
// setting to the highest resolution available
screen.currentMode = highestWidthMode;
NSLog(#"screen.currentMode = %#", screen.currentMode);
screen.overscanCompensation = UIScreenOverscanCompensationScale;
// initializing screen
secondWindow = [[UIWindow alloc] initWithFrame:[screen bounds]];
[secondWindow setScreen:screen];
// other view is a UIViewController, just remember to return NO in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation or the iOS will rotate the frame.
UIViewController *vc = [[OtherView alloc] initWithNibName:#"OtherView" bundle:nil];
secondWindow.rootViewController = vc;
[secondWindow makeKeyAndVisible];