xcode 6 ios 8 uiimageview - uiimageview

I want to update my old app for ios 8 and new devices. So i just tested my app on xcode 6 ios 8 simulator. Everything was good except one thing. I have a button in my app and when i press it it should open an image on an uiimageview. It is working on ios 7.
Here is my code:
- (IBAction)circlebutton1:(UIButton *)sender{
NSUInteger index = [circleImages indexOfObject:_circlebutton1.accessibilityLabel];
if(changenumber != 1){
NSLog(#"#1");
if(_rectangle1.image == [UIImage imageNamed:#"emptyslot.png"]){
NSLog(#"#2");
_rectangle1.image = [UIImage imageNamed:[rectangleImages objectAtIndex:index]];
_rectangle1.accessibilityLabel = rectangleImages[index];
}
...
}
First nslog appears but the second one not. So the problem is about if statement i guess.
But i can't figure out. Hope you guys help me.
Best Regards,
Taha

Finally i realised that i missed a little part of documentation about uiimage.
"You must use isEqual: to correctly test for equality"
if([_rectangle1.image isEqual: [UIImage imageNamed:#"emptyslot.png"]])

Related

iOS 9 Bug when using presentViewController "EXC_BAD_ACCESS code=2"

First. IT WAS working until this last update from Apple. So in theory it should still work.
Here's the code:
CarouselViewController *cViewController = [[CarouselViewController alloc] initWithContent: edition];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: cViewController];
[self presentViewController: nav animated: YES completion:nil];
The reason i'm doing it is because i need this new window to be presented in fullscreen and not inside this ViewController (the caller) which is occupying half of the screen.
So, HOW can i fix this? And why BEFORE it was working and now with this silly iOS 9 update it isn't?
My guess (and that's all it is with the limited information presented) is that the root cause of the problem has something to do with CarouselViewController and it's view actually being loaded and presented on screen.
That is what is happening in your app during this line
[self presentViewController: nav animated: YES completion:nil]
I would set a breakpoint in that ViewController subclass loadView/viewDidLoad or check out it's Nib/Storyboard.

Unexpected nil window in _UIApplicationHandleEventFromQueueEvent

One of my old apps is not working with iOS8. When I start the app up, and try to tap on the screen anywhere, I get this message in my console:
unexpected nil window in _UIApplicationHandleEventFromQueueEvent,
_windowServerHitTestWindow: <UIWindow: 0x7fe4d3e52660; frame = (0 0; 320 568);
opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fe4d3e2c450>;
layer = <UIWindowLayer: 0x7fe4d3e86a10>>
I'm using an old style MainWindow.xib. In the MainWindow.xib is my Window object, as well as a UINavigationController which has its first View Controller defined within as well. The image below is showing the Outlets connected to the App Delegate.
The white "view" in the screenshot below is the UIWindow. The view on the right is the UINavigationController (nav bar hidden) with the first ViewController defined inside it.
How do I fix this without recreating the entire app from scratch with a new project?
EDIT: I just discovered there is a TINY strip wherein my buttons will actually receive their taps/clicks.
I've also noticed that my self.view.window is nil. How do I make sure that is set?
Additional to B H answer. Also look this answer.
Got this issue when launching my landscape only app from portrait orientation (also the app shouldn't be presented in recently opened apps list, which can be seen by pressing Home button twice. Perhaps, iOS somehow caches the orientation and window size).
My code was
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
I set W+H autoresizing mask for window, it didn't help me, because the window don't being resized on rotation, but the transform matrix is changed.
The solution is simple
self.window = [UIWindow new];
[self.window makeKeyAndVisible];
self.window.frame = [[UIScreen mainScreen] bounds];
So the frame is set AFTER the window get its orientation from root view controller.
You don't have to add any code to fix this.
Open the main xib file and find "Window" from the left side and enable Visible at Launch and Full Screen at launch.
Check out your Window nib file and make sure it is taking up the full screen. I had a similar issue on my app where touch events weren't being registered on a strip on the right side. Once I set my MainWindow.xib to take up the Full Screen, I had no more errors and touch events were working again. My app was also being displayed in Landscape but my MainWindow.xib had portrait dimensions.
Sometimes it's just simple setting that's missing some value: Click on Project(whatever you named your project) name item then make sure General tab is selected and scroll to the bottom. Look for App icons and Launch Images make sure there is some value in the Launch Screen File field, this should be either Main or LaunchScreen
In case somebody finds this useful:
In my case, I had used
self.window = [[UIWindow alloc] init];
instead of
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
and that was the reason for the problem.
I was getting this error on an old app that did not have the Default-568h#2x.png launch screen. When the taller iPhones were first introduced, this was the signal to iOS that the app could handle the new geometry. Otherwise, it was displayed in a 320x480 window. Funny, I did not even notice the app was not using the full screen.
I wasn't able to test efpies solution, but the way I fixed it in my app was to replace the MainWindow.xib with a Storyboard.
We had the same issue, and we tried the proposed solutions in this thread without success.
What ended up working for us, was to re-write the logic to be pure programmatically instead of using xib's. After this we don't see the 'unexpected nil window' error and the view is getting the hit all over the screen.
In case this helps anyone else that stumbles here, I also got this error when I had the UIScreen.mainScreen().bounds size flipped when setting the window's frame.
I am also upgrading my old project to iOS 7 and iOS 8.
Actually, I don't use MainWindow.xib, but creating window manually in application:didFinishLaunchingWithOptions:.
But i have same unexpected nil window in _UIApplicationHandleEventFromQueueEvent error after launch.
So, in my case, problem was solved by changing deployment target to 6.0 and replacing code in main.m:
Old main.m:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
New main.m:
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegate class]));
}
}
In my case it was an old code and after reading the complete code i found this line
UIApplication.shared.delegate?.window??.isUserInteractionEnabled = false
I handle it according to my logic and it's working now.
It worked for me to Enable windows user interaction.
window.isUserInteractionEnabled = true
Using the new ios 8 'nativeBounds' UIScreen property instead of 'bounds' when creating the window fixed the issue for me. No other changes required.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] nativeBounds]] autorelease];
To support previous version too, I do a runtime check with the version:
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

Trouble with UIScrollView in iOS 8 GM

I'm developing and iOS app which I started with iOS 7 and now tried to migrate to iOS 8. Everything works nicely except UIScrollViews. My app has a navigation bar and it seems to affect to UIScrollViews. Indeed, the content inside the view is pulled down the approximate space that a navigation bars occupies. The weird thing is that the same app running on iOS 7 doesn't cause any sort of problem related to that.
I've made a simple code to test if the problem was my app, but the problem is still there. Here it is my code:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 65, self.view.frame.size.width, self.view.frame.size.height-65)];
scroll.layer.borderWidth = 2.0f;
scroll.layer.borderColor = [UIColor greenColor].CGColor;
[self.view addSubview:scroll];
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"searching1.png"]];
[scroll addSubview:image];
image.frame = CGRectMake(100, 0, 100, 100);
And that's the result, as you can see the image is not at point (0, 100):
I don't know how to deal with this problem. Moreover, iOS 8 is now in GM, so I don't know if this is a real bug or a SDK change.
The error was caused by the propety
self.automaticallyAdjustsScrollViewInsets
Turns out that in iOS 7 it was automatically set to false, but now in iOS it is true by default. So setting it explicitly to false solved the problem and the app is running well in both platforms.

What information does the game center return after finding players?

I am currently experimenting on raywenderlich's project of How To Make a Multiplayer iPhone Game Hosted on Your Own Server Part 1
at the end of the part 1 tutorial, it claims that after looking for auto-match via the game center panel, the log panel would show 2 PlayerIDs
CatRace[5407:707] didFindPlayers
CatRace[5407:707] G:1036727375
CatRace[5407:707] G:1417937643
However, when I tried to run on the iPhone Simulator and my iPhone, it always returns only 1 playerID after finished matching players.
So, I would like to know exactly how the function would return the information.
Could anyone help on this ?
Additional:
I found that the simulator and the iDevice found the player of another, but not including itself. Is it the normal case?
Already tried to put the server on to an external host. Still No luck, returning only one player in the array.
Is this function
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray *)playerIDs
supposed to return all the players including the local player ?
Although it is so wired, I manage to manipulate the return into a new NSMUTABLEARRAY and send to the hosting server.
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray *)playerIDs {
NSMutableArray *players = [[NSMutableArray alloc] initWithArray:playerIDs];
[players insertObject:[GKLocalPlayer localPlayer].playerID atIndex:0];
if (_state == NetworkStatePendingMatch) {
[self dismissMatchmaker];
[self sendStartMatch:players];
}
[players release];
However, I am still looking for the answer of my original question, which is the supposed return of - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray *)playerIDs

UITabBarController disappear in Three20 TTThumbsViewController

I'm having trouble put TTThumbsViewController and UITabBarController together. The tab bar will disappear when switched to TTThumbsViewController of Three20. I've read all questions in stack overflow and nothing really helped. And I even tried to set all
self.wantsFullScreenLayout = NO;
self.hidesBottomBarWhenPushed = NO;
in my thumbsviewcontroller and in Three20UI project. None of these methods work.
I'm building my app in Xcode4 with storyboard and adding this thumbs gallery is the last part.
I realise this is an oldish post but if you use:
self.wantsFullScreenLayout = NO;
self.hidesBottomBarWhenPushed = NO;
IT means that the push has already taken place therefore negating the command. Use this instead:
GalleryViewController *gallery = [[GalleryViewController alloc] init];
gallery.wantsFullScreenLayout = NO;
gallery.hidesBottomBarWhenPushed = NO;
Then push it. This works.
I ended up solving this problem by remove the three20 navigation bar in my code and simply use the uinavigationcontroller in storyboard. I don't know why, but problem solved. I hope this can help those like me using storyboard with three20.

Resources