How to implement ckrefreshcontrol to support ios5? - xcode

I've seen in this question that CKRefreshControl can be used as a substitute for UIRefreshControl for apps that support both iOS5 and iOS6. I've found the code on Github, but I don't know how to implement it. John said to just use the same code. But something is missing. Where does the CKRefreshControl code go?
self.refreshControl = [[UIRefreshControl alloc] init];
Thanks!

There is no specific CKRefreshControl code needed other than the CKRefreshControl source itself. When CKRefreshControl was first released you had to replace all calls to UIRefreshControl with calls to CKRefreshControl, and then it automatically dispatched to the correct class based on whether you were on iOS 5 or on iOS 6+.
However, with the recent contributions from John Haitas, that is no longer necessary. Instead, simply compiling and linking against the CKRefreshControl source code makes the UIRefreshControl class available when targeting iOS 5. As a result, you can simply continue to use [[UIRefreshControl alloc] init], and it will automatically work on iOS 5.
Why should you believe me? Because I'm the guy who wrote CKRefreshControl in the first place.

1) Add the 3 classes and prefix to your project:
- CKParagraphStyle.h and CKParagraphStyle.m
- CKParagraphStyle.h and CKRefreshArrowView.m
- CKRefreshControl.h and CKRefreshControl.m
- CKRefreshControl-Prefix.pch (goes into TableVCs using Refresh).
2) Add the QuartzCore.framework to the target libraries.
3) Add this method:
-(void)doRefresh:(CKRefreshControl *)sender {
NSLog(#"refreshing");
[self.refreshControl performSelector:#selector(endRefreshing) withObject:nil afterDelay:1.0];
}
Finally, use UIRefreshControl, as usual, but select the doRefresh method:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(doRefresh:) forControlEvents:UIControlEventValueChanged];

Related

UISwitch doesn't work on Google Maps SDK for iOS?

I'm trying to create a UISwitch laid on mapView_ of Google Maps for my iOS app, but it seems not to work.
In details, I first followed instruction from google, created mapView_, then made it my viewcontroller's view:
self.view = mapView_;
Then, I created an UISwitch programmatically and added it as a subview:
mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(50, 360, 0, 0)];
[mySwitch setBackgroundColor:[UIColor clearColor]];
[mySwitch addTarget:self
action:#selector(changeSwitch:)
forControlEvents:UIControlEventTouchDown];
[mapView_ addSubview:mySwitch];
But when I touched the switch both in simulator and device, it didn't change its state from ON->OFF or OFF->ON. I even tried different UIControlEvent, such as UIControlEventValueChanged but it didn't work. To make sure that the code should work, I tried on a normal view of a normal test viewcontroller (that means, not using google maps), it worked fine!
Does anyone have any comment about this issue?
Thanks heaps!
You can work around this issue by adding both the UISwitch and the GMSMapView to a single UIView parent, instead of adding the UISwitch as a child of a GMSMapView. Yes, this means you need to position both the GMSMapView and the UISwitch.

XCode analyzer not working

I am currently doing the CS193P lessons via iTunesU and the teacher mentioned the Build and Analyze option several times. He said that it was a nice tool and fun to play with.
So I tried, and noticed that it doesn't work, or that I don't understand how it should work (I think the last option).
I have a few memory leaks, and it is not warning me at all! I saw online that a blue thing should appear telling me it is a leak, but I don't see anything although I'm doing NSDictionary *dict = [[NSDictionary alloc] init];.
How is it supposed to work? From what I read on the internet I thought it should signal potential leaks. What am I doing wrong?
I'm using XCode 3.2.5.
Thanks.
Update:
This is a kind of bug, I think.
When I declare this in the interface like NSDictionary *dict; and initialize it (but nowhere deallocating it) it says nothing.
When I declare and initialize it in - (void) init and don't release it in there like:
- (void) init {
if(self = [super init])
NSDictionary *dict = [[NSDictionary alloc] init];
return self;
}
It does signal a leak. Why? Is this because of my settings? Is this a bug? If it is a bug, where and how should I report it?
It's giving you a warning because you're not deallocating it.
-(void)dealloc{
[super dealloc];
[dict dealloc];
}
It's not warning you because you should be able to release the objects as soon as you create them, and the analyzer goal is to alert you on possible leaks in your code.
You can either use autorelease, or you dealloc the object you create manually.
P.S., little curiosity: why are you using Xcode 3.2.5?
Don't know exactly if that version can, but in the latest versions of Xcode, when you run that tool, you are able to see WHAT object you are deallocating with the means of some arrows with explanation, something like
I just found out that a reboot and restart of Xcode will bring it back.

Adding events to calendar in ios 5 programatically

eventStore=[[EKEventStore alloc] init];
EKEvent *addEvent=[EKEvent eventWithEventStore:eventStore];
addEvent.title=#"hello";
addEvent.startDate=messageDate;
addEvent.endDate=[addEvent.startDate dateByAddingTimeInterval:600];
[addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
addEvent.alarms=[NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]];
[eventStore saveEvent:addEvent span:EKSpanThisEvent error:nil];
The code above works fine in ios 4.2 but not in ios 5. I have the code in applicationDidfinishingLaunching method. Due to error, black screen appears and app exits. Only recurrenceRules has changed in ios 5 and I have not made use of it. All other properties are available in superclass EKCalendarItem. I cannot test it since I have xcode 3.2 and snow leopard. I am looking to debug the line at which error occurs causing the app to quit. I doubt it is related to setCalendar or using alarms property.
The code is correct and works in iOS 5. The reason for my error was the first line
eventStore=[[EKEventStore alloc] init];
Since initializing eventstore takes some time, placing it in application launch method resulted in time out. I found it from my crash report stating:
"Elapsed application CPU time (seconds):30 seconds"
The app is supposed to launch within 10 seconds. if not time out occurs with Exception Codes: 0x8badf00d
You have to use 5th version of SDK. You can find a diff in saveEvent function:
[eventStore saveEvent:addEvent span:EKSpanThisEvent commit:YES error:nil];
It should help you.
There was a change (I believe) to the API in iOS5 that requires you to add EKAlarm objects using the addAlarm instance method.
To add an alarm to your event in iOS5:
[addEvent addAlarm:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]]
Check EKCalendarItem Class Reference for details.
Although #property(nonatomic, copy) NSArray *alarms is not specified as read only it would appear to be behaving that way.
See https://stackoverflow.com/a/7880242/816455 for more information on other iOS5 EKAlarm issues.
NaveenaRK I wasn't having any time out errors however i fixed this by doing the following.
You need to keep the eventStore in memory for the objects life time.
eventStore = [[EKEventStore alloc] init]
I initialised the event store on creating the object and released it in dealloc. The problem with setting the alarms and the "CADObjectGetInlineStringProperty" error were both fixed.

How to change an NSTableView's selection without using deprecated methods

I have the Apress "Learn Cocoa" book (published in 2010 BTW) and I am getting a deprecation error on one of the lines. The code is:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.villain = [[NSMutableDictionary alloc] initWithObjectsAndKeys:#"Lex Luthor", kName, #"Smallville", kLastKnownLocation, [NSDate date], kLastSeenDate, #"Superman", kSwornEnemy, #"Revenge", kPrimaryMotivation, [NSArray arrayWithObjects:#"Intellect", #"Leadership", nil], kPowers, #"Superhero Action", kPowerSource, [NSNumber numberWithInt:9], kEvilness, [NSImage imageNamed:#"NSUser"], kMugshot, #"", kNotes, nil];
self.villains = [NSMutableArray arrayWithObject:self.villain];
[villainsTableView reloadData];
[villainsTableView selectRow:0 byExtendingSelection:NO];
[self updateDetailViews];
}
I am getting the error on the 2nd to last line and I don't know exactly what that line is intending to do.
The replacement for the deprecated method would look like this:
[villainsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
The documentation tells you what that message does and what the replacement is.
In XCode you can place the mousecursor above the symbol you want to know something about. While placing the mousecursor above this symbol (i.e. NSString), hold down the ALT-Key and doubleclick. This will open up a context sensitive documentation. All deprecated methods and symbols are marked red there. Mostly the new replacement is documented next to the old one. In the new xcode, a popup-window will appear. The doc will be opened by clicking the "notebook"-icon at the border of the box.
i.e. for NSString you will find:
– initWithCString: Deprecated in iOS 2.0
+ stringWithCString:encoding:
With an educated guess you will choose "+ stringWithCString:encoding:"
Apple almost adds new functionality which is a logical augmentation of the old stuff, so you don't need to google hard, but watch into the method summary of the related doc.

IBPlugin: Adding additional objects on drag from IB Library

I have a list view class that just like NSCollectionView requires an additional prototype item and a prototype view to be of any use.
When dropping an NSCollectionView from the library in Interface Builder those two helper items are automatically created. However I couldn't find a single official Apple document dealing with this use case (describing how its done).
Digging thru the Apple Dev Guides I could however find "ibDidAddToDesignableDocument:".
With the following code I managed to get my auxiliary items created on drop from library:
- (void)ibDidAddToDesignableDocument:(IBDocument *)document {
[super ibDidAddToDesignableDocument:document];
NSView *prototypeView = [[[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 65.0)] autorelease];
DLListViewItem *prototypeViewItem = [[[DLListViewItem alloc] initWithNibName:nil bundle:nil] autorelease];
[document addObject:prototypeViewItem toParent:nil];
[document addObject:prototypeView toParent:nil];
[document connectOutlet:#"view" ofSourceObject:prototypeViewItem toDestinationObject:prototypeView];
[document connectOutlet:#"listView" ofSourceObject:prototypeViewItem toDestinationObject:self];
[document connectOutlet:#"prototypeItem" ofSourceObject:self toDestinationObject:prototypeViewItem];
}
However…
…IB adds those aux items for NSCollectionView only on the actual initial drag from the library, not on any other call of "ibDidAddToDesignableDocument:", such as when embedding, copying or duplicating the item. (while my method would, and on all)
This makes me wonder whether Apple actually uses "ibDidAddToDesignableDocument:" for this and if I'm on the right track with this at all.
How does one imitate this properly? I'm having a hard time trying to distinguish between different contexts for "ibDidAddToDesignableDocument:". Anybody successfully done this?
Unfortunately none of Google, Google Code, GitHub, or the documentation revealed anything helpful, so I'm in desperate need of help here. :(
Thanks in advance!
Edit: Oh great, this question just brought me the tumbleweed badge, yay! Not.
I'm more into useful answers actually, but thanks anyway ;)
I struggled with this on a plugin I did myself a while ago. In my case I was able to check a property of the object to see if it had been initialized already and skip adding the auxilliary objects in that case. I believe BWToolkit uses some internal checking that is similar. Couldn't you check your object's 'prototypeItem' property to see if you need to skip creating your aux objects?

Resources