Apple - UISearchBar issue with UINavigationConroller - uinavigationcontroller

Using storyboard I have created one UINavigationController and two UITableViewContorllers:
(MasterViewContoller)
and
(Level2Contoller).
Both UITableViewControllers have UISearchBar at top. MasterViewContoller is set as root of UINavigationConroller.
Now the problem is that when I use below code to go to level2, I am not getting a seach bar on Level2Contoller.
level2Contoller *l2 = [[level2Contoller alloc]init];
[[self navigationController] pushViewController :l2 animated:YES];

Solution:
I used this:
level2Contoller * level2Contoller = [self.storyboard instantiateViewControllerWithIdentifier:#"id1"];
instead of:
level2Contoller *l2 = [[level2Contoller alloc]init];

Related

NSAttributedString drawRect doesn't draw images on-screen on Mojave

I have a working app that draws NSAttributedStrings into a custom view. The NSAttributedStrings can included embedded images. This works on versions of macOS prior to Mojave. The app can display the strings on screen, print them, and save them to image files.
This is apparently broken under Mojave. Weirdly, printing and saving to image files still works; but on-screen, the strings display only the text and not the embedded images. Proper space is left for the images, but that space is blank.
I've tested by building a small app that shows a window with an NSTextField (a label) and a custom view. It makes a single NSAttributedString with an embedded image. It applies that string to the attributedStringValue of the label, and also calls drawInRect: on the same string in the drawRect: method of the custom view. In the label, the string is displayed correctly, image and all. But in the custom view, only the text appears, and the space where the image should be is blank.
Anybody got a clue why this is happening on Mojave but not on earlier versions of macOS?
Here is the code that makes the string (and caches it, for re-use):
static NSMutableAttributedString* sgAttrString = nil;
/*
* Creates an attributed string the first time it's called,
* then returns that same string each time it's called.
*/
+ (NSAttributedString*)getAttributedString
{
if (sgAttrString == nil)
{
NSFont* font = [NSFont fontWithName:#"Helvetica" size:24.0];
NSDictionary *attrs = #{
NSFontAttributeName: font
};
sgAttrString = [[NSMutableAttributedString alloc] initWithString:#"Daisy: " attributes:attrs];
NSImage* daisy = [NSImage imageNamed:#"daisy.png"];
[daisy setSize:NSMakeSize(24,24)];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
// I'm aware that attachment.image is available only on macOS 10.11 and later.
// It's not an issue in my real project.
attachment.image = daisy;
NSMutableAttributedString* imageStr = [[NSMutableAttributedString alloc] init];
[imageStr setAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
[sgAttrString appendAttributedString:imageStr];
[sgAttrString appendAttributedString: [[NSAttributedString alloc] initWithString:#" !!" attributes:attrs]];
}
return sgAttrString;
}
Here is the code that applies the string to the NSTextField:
NSAttributedString* str = [Utilities getAttributedString];
self.label.attributedStringValue = str;
And here is the code that draws the string in a custom NSView:
NSAttributedString* str = [Utilities getAttributedString];
[str drawInRect:NSMakeRect(50,50, 300, 40)];
Again, this behavior seems to occur only in Mojave! Thanks in advance for any help.

watchkit WKAlertAction openSystemURL

I am trying to show the User different Phone Numbers on Apple Watch and he clicks on one than phone call alert should appear. I'll do it like this but the Alert is just dismissed without call action:
NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:0];
WKExtension *myExt = [WKExtension sharedExtension];
for (NSString *phone in arr) {
NSString *tel = [NSString stringWithFormat:#"tel:%#",phone];
WKAlertAction *act = [WKAlertAction actionWithTitle:tel style:WKAlertActionStyleDefault handler:^(void){
[myExt openSystemURL:[NSURL URLWithString:phone1]];
}];
[tempArray addObject:act];
}
NSString *titleMessage = #"Call";
NSString *textMessage = #"Please select the number you want to call.";
NSString *cancel = #"Cancel";
WKAlertAction *act = [WKAlertAction actionWithTitle:cancel style:WKAlertActionStyleDestructive handler:^(void){
}];
[tempArray addObject:act];
[self presentAlertControllerWithTitle:titleMessage message:textMessage preferredStyle:WKAlertControllerStyleAlert actions:tempArray];
Buttons are shown as expected and the Handler is also called with the correct Phone Number. But it does not openSystemURL. Does somebody know why and how to fix? Thanks!
I think you forgot to add "tel" scheme ,Use below code :
[WKAlertAction actionWithTitle:#"tel" style:WKAlertActionStyleDefault handler:^(void){
[[WKExtension sharedExtension]openSystemURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",#"YOUR NUMBER"]]];
}];
About Apple URL Schemes

NSTableCell setDataCell disables editing

I have a NSTableView which I dynamically add columns. I've just added a call to setDataCell to customize my cell. The code looks like:
for(NSUInteger columnIndex = 0; columnIndex < resultSet.columNames.count; ++columnIndex)
{
NSTableColumn * newColumn = [[NSTableColumn alloc] initWithIdentifier: [NSString stringWithFormat: #"%ld", columnIndex]];
[newColumn.headerCell setAlignment: NSCenterTextAlignment];
[newColumn.headerCell setStringValue: resultSet.columNames[columnIndex]];
[newColumn setDataCell: [[HSDisclosureTextFieldCell alloc] init]];
[newColumn setEditable: YES];
[resultsTableView addTableColumn: newColumn];
if(newColumn.width < 60) [newColumn sizeToFit];
} // End of column loop
If I remove the call to setDataCell then I can still double click my entry and edit it.
I have minimized the HSDisclosureTextFieldCell contains the following (no overrides):
#interface HSDisclosureTextFieldCell : NSTextFieldCell
{
}
But I still cannot double click to edit the field anymore.
Any ideas where I'm going wrong?
Turns out even though I am doing:
[newColumn setEditable: YES];
and have:
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
implemented, I needed to switch my setDataCell to be:
HSDisclosureTextFieldCell * cell = [[HSDisclosureTextFieldCell alloc] init];
[cell setEditable: YES];
[newColumn setDataCell: cell];
Now that I have done that, everything seems to be working properly.

how can i Draw a line in ios map using overlayer

I want to draw a line on ios map using overlayer. I have one code for draw a line on map. But it is not working for me. Can any one help me.
MKCoordinateSpan span;
span.latitudeDelta=.03;
span.longitudeDelta=.03;
MKCoordinateRegion region;
region.span=span;
region.center=CLLocationCoordinate2DMake(39.046259, -76.851195);
[_myMapView setRegion:region animated:YES];
[_myMapView regionThatFits:region];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapWebView:)];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[self.myMapView addGestureRecognizer:singleTap];
[singleTap release];
CLLocationCoordinate2D commuterLotCoords[5]=
{
CLLocationCoordinate2DMake(39.036399,-76.872208)
};
MKPolygon *commuterParkingPolygon=[MKPolygon polygonWithCoordinates:commuterLotCoords count:5];
[_myMapView addOverlay:commuterParkingPolygon];
In this above code we can change the end point from this line"CLLocationCoordinate2DMake(39.036399,-76.872208)" But in always the start point is
lat 0.000003, long 0.000000. how can i change the start pint. Could any one help me to solve this issue.

How to navigate next tab while first tab view in process?

I have 4 tabs in UITabBarcontroller. My problem is i need to navigate to next tab by user click while first tab process in on going?? how to run the process on background??
Now second tab not working while the first tab view in process. I used PerformSelectorInBackground but it's not help me?? Can any one help me Please????
Am poor in english, can you understand my problem?
Yuva.M
Run your heavy process with NSThread.
Snippet from here:
- (IBAction) startThreadButtonPressed:(UIButton *)sender {
[NSThread detachNewThreadSelector:#selector(startTheBackgroundJob) toTarget:self withObject:nil];
}
- (void)startTheBackgroundJob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
[NSThread sleepForTimeInterval:3];
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + 0.01;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
}

Resources