2013年8月29日星期四

iOS7 TableView layout bug with UITableViewWrapperView

When working with a special problem with iOS7 Beta5, my cells in one of my tableviews is not right.
All cells' position y in screen is much higher than it should be.
Than I find that 'UITableView now initially has a subview (UITableViewWrapperView), it's allUITableViewCells' superview.'
And after tableview's initialization, I print UITableViewWrapperView
po [_messageTableView.subviews objectAtIndex:0]
<UITableViewWrapperView: 0x1814a690; frame = (0 -117; 0 117); autoresize = W+H; layer = <CALayer: 0x1814a660>>
so the following code can fix this problem
for (UIView *subview in tableView.subviews)
    {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewWrapperView"])
        {
            subview.frame = CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height);
        }
    }
Done!
Have fun on the way fighting with new changes and bugs of iOS7 :).

------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com

Changes and bugs finded when adapting iOS7 Beta5

1. UISearchBar now initially has a subview (UIView) which contains UISearchBarBackground and UISearchBarTextField inside it.
2. UITableView now initially has a subview (UITableViewWrapperView), it's all UITableViewCells' superview. So be careful with codes that call cell's superview.
3. The contentSize of a UITextField is not reliable, so UITextField.contentSize.width or height is not the value you want.


------

My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com

2013年7月9日星期二

Event Kit, A Glance

As my project needs to add Event to Calendar in iOS System, I have a chance to take Event Kit a glance. It's available from iOS4.0, and get full function in iOS6.0.

First Add EventKit.framework to your project. Then add a new Event like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// First get the event store object
    EKEventStore *eventStore = [[EKEventStore alloc] init];
    // Then create a new event
    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    // Set the start and end date
    NSDate *startDate = [NSDate date];
    NSDate *endDate  = [NSDate date];
    // Set properties of the new event object
    event.title     = @"Your Event Tittle Here";
    event.startDate = startDate;
    event.endDate   = endDate;
    event.allDay    = NO;
    event.location  = @"Your Event Location";
    // Set event's alarm
    EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:[NSDate date]];
    [event addAlarm:alarm];
    // Set event's calendar to the default calendar
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
    // Create an NSError pointer & save the event
    NSError *error;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&error];
    // Here get eventIdentifier and stroe it for further use
    // like remove event
    //event.eventIdentifier;
Using the eventIdentifier string to delete the event like this:
1
2
3
4
5
6
7
8
9
10
11
12
if (eventIdentifier && [eventIdentifier length]>0)
    {
        // Get the event store object
        EKEventStore *eventStore = [[EKEventStore alloc] init];
        // Get event with eventIdentifier we get when the event is create.
        EKEvent *event = [eventStore eventWithIdentifier:eventIdentifier];
        if (event)
        {
            // Remove event
            [eventStore removeEvent:event span:EKSpanThisEvent error:&error];
        }
    }
You can use EKEventEditViewController in EventKitUI.framework to add new event.
1
2
3
4
5
6
7
8
// Get the event store object
    EKEventStore *eventStore = [[EKEventStore alloc] init];
    // Create the EditViewController
    EKEventEditViewController* controller =[[EKEventEditViewController alloc] init];
    controller.eventStore = eventStore;
    controller.editViewDelegate = self;
    [self presentModalViewController: controller animated:YES];
    controller = nil;

------
My new business with my wife, wholesale meddle-to-high end men's seamless underwear in the Netherlands: https://ecosharelife.com