jeudi 13 août 2015

How to update the color of section title without uitableview reloadData

I'm using willDisplayHeaderView to change the color of section title:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {

    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    header.textLabel.textColor = [UIColor grayColor];
}

Now, I want to update the color of a section title, how to do it without [tableview reloadData]?



via Chebli Mohamed

Building An RTP Server in iOS That Allows WiFi Speakers To Stream Music

A Little Background On Why I Have To Do This

I am currently optimising an app in order to improve the transferring of media files to the WiFi speakers that our team developed. Our solution before was using iPhone as an HTTP server and then allow the speakers to connect and download music from it. But unfortunately a lot of problems occurred such as frequent slow transfer speed, file read failure, and when user uses the "seek" command, the speakers would have to download the whole file in order for it to seek into that particular time before it starts to play. This is a very bad experience for our users.

What I Need

In order to solve the problem I mentioned above. We thought of changing the HTTP server to an RTP server that will be ran on an iPhone and then allows the WiFi speakers to stream music from it. However, from what I read on other Q&A platforms they mentioned that iPhone does that support transferring of data using RTP. I also tried searching here in stack but were not able to find an answer that solves my problem.

My Question

Is it possible to run an RTP server on iPhone and is there any demo about this that I can refer to?

Any suggestions would be high appreciated.



via Chebli Mohamed

how to handle ContentSizeCategoryDidChangeNotification more elegant

I have a navigation bar, and set its title with preferredFontForTextStyle, And register for UIContentSizeCategoryDidChangeNotification, but every time, when deal with this notification, I have to reset the titleTextAttributes of the navigation bar to get the title bar updated when I change the Lager Text in accessibility in settings, I just want to know if there is a elegant way to update the title, the code is just below:

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.navigationBar.titleTextAttributes = [
        NSFontAttributeName: UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline),
        NSForegroundColorAttributeName: List.Color.Gray.colorValue
        ]

        NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleContentSizeCategoryDidChangeNotification:", name: UIContentSizeCategoryDidChangeNotification, object: nil)
   }

    // MARK: Lifetime

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self, name: UIContentSizeCategoryDidChangeNotification, object: nil)
    }

    // MARK: Notifications

    func handleContentSizeCategoryDidChangeNotification(_: NSNotification) {
        navigationController?.navigationBar.titleTextAttributes = [
        NSFontAttributeName: UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline),
        NSForegroundColorAttributeName: List.Color.Gray.colorValue
        ]
    }

PS. I tried to call setNeedsLayout() and call layoutIfNeeded() of the navigation bar, but it doesn't update the title font, the upper method is fine, but i want a more elegant solution, like call a method from apple.

Thanks



via Chebli Mohamed

Parse local data store in Dating App like badoo. Urgent

Hello, iam develooing an Dating App like baddo with Parse and i want to store data to be accesible offline (Users find near you, Messages list e Conversations) 1. How to activate in AppDelegate and in ViewsControllers? 2. Give me and simple exemple with my own code if possible. Thanks

Messages list viewController

PFQuery *messageQueryFrom = [MessageParse query];
[messageQueryFrom whereKey:@"fromUserParse" equalTo:[UserParseHelper currentUser]];
PFQuery *messageQueryTo = [MessageParse query];
[messageQueryTo whereKey:@"toUserParse" equalTo:[UserParseHelper currentUser]];
PFQuery *both = [PFQuery orQueryWithSubqueries:@[messageQueryFrom, messageQueryTo]];
[both orderByDescending:@"createdAt"];

[both findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)

Conversation Viewcontroller

 (void)getMessages

PFQuery *query1 = [MessageParse query];
[query1 whereKey:@"fromUserParse" equalTo:[PFUser currentUser]];
[query1 whereKey:@"toUserParse" equalTo:self.toUserParse];
[query1 whereKey:@"text" notEqualTo:@""];


PFQuery *query2 = [MessageParse query];
[query2 whereKey:@"fromUserParse" equalTo:self.toUserParse];
[query2 whereKey:@"toUserParse" equalTo:[PFUser currentUser]];
[query2 whereKey:@"text" notEqualTo:@""];




PFQuery *orQUery = [PFQuery orQueryWithSubqueries:@[query1, query2]];
[orQUery orderByAscending:@"createdAt"];





[orQUery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    self.messages = [objects mutableCopy];
    [self.collectionView reloadData];
    [self scrollCollectionView];
    for (MessageParse *message in objects) {
        message.read = YES;
        [message saveInBackground];
    }
}];

User near viewcontroller

(void)queryParseMethod {NSLog(@"start query");

PFQuery *query = [UserParseHelper query];
[query whereKey:@"username" notEqualTo:self.mainUser.username];
PFGeoPoint *userGeoPoint = self.mainUser.geoPoint;

[query whereKey:@"geoPoint" nearGeoPoint:userGeoPoint];

if (self.segmentedControl.selectedSegmentIndex == 0) {
    [query whereKey:@"isMale" equalTo:@"true"];

}
if (self.segmentedControl.selectedSegmentIndex== 1) {
   [query whereKey:@"isMale" equalTo:@"false"];

}


PFUser *chekUser = [PFUser currentUser];
NSString *vip = chekUser[@"membervip"];
if ([vip isEqualToString:@"vip"]) {

    NSLog(@"Unlim - vip member");
    self.upgradeVip.hidden = YES;

} else{

    NSLog(@"No Unlim - no vip member");
 //   query.limit = limitQueruNoVipUser;
    self.upgradeVip.hidden = NO;

}

[query whereKey:@"geoPoint" nearGeoPoint:self.mainUser.geoPoint withinKilometers:self.mainUser.distance.doubleValue];



[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        imageFilesArray = [[NSArray alloc] initWithArray:objects];


       [_imagesCollection reloadData];
        [_imagesCollection performBatchUpdates:nil completion:nil];
    }
}];

}



via Chebli Mohamed

PersonViewController in TabBarController

I have a UITabBarController with three tabs. When a certain one is pressed, I'd like the user to immediately see a person view controller (an instance of the ABPersonViewController class).

I don't want to just use the presentViewController() method with a person view controller as a parameter because this results in a lag, when the user can see the underlying view controller from which it's presented.

I also can't make the view controller inherit from ABPersonViewController, because it's set by Apple so that it can't be subclassed. Is there a way I can accomplish this?



via Chebli Mohamed

How do I fit a UISearchBar in a UIBarButtonItem?

I'm using a UISearchController in iOS 8 and when I make its UISearchBar my table's header view everything is fine. However now I need it in my UINavigationBar's left bar button (can't be the title view because of the vertical centering when I enlarge the nav bar). When I wrap the UISearchBar in a UIBarButtonItem it is larger than the width of the screen.

off screen search bar

I think it is related to my view controller initialized from a storyboard with size classes enabled which means my frames are not set till viewDidLayoutSubviews. However I had the same issue with my segmented control in a toolbar and I just called sizeToFit on the toolbar in viewDidLayoutSubviews and that fixed the toolbar. When I do the same for the search bar it still draws partly off screen. Apple does this in some of their iPad apps but how?

Note: I can hack it to get it all on screen but I have to wrap it in another view but then the color is off and it just seems wrong and I think the animation is off.



via Chebli Mohamed

Swift: Screenshot without Tab Bar

I know it's fairly easy to take a screenshot of the entire screen, with or without the navigation and status bars, using a UIGraphicsImageContext but is there a way to take one (or crop one) so that the navigation bar is visible, but the status bar and tab bar are not visible?



via Chebli Mohamed