我知道如何删除/更改UISearchBar搜索字段周围的背景颜色:
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview];
self.searchBar.backgroundColor = [UIColor grayColor];
Run Code Online (Sandbox Code Playgroud)

但是不知道如何在里面这样做:

这需要与iOS 4.3+兼容.
我有一个像这样定义的字符串常量:
#define kMyString @"This is my string text!";
Run Code Online (Sandbox Code Playgroud)
代码中的某处我想用NSLog打印出这段代码:
NSLog(@"This is it: %@",kMyString);
Run Code Online (Sandbox Code Playgroud)
但是得到一个构建错误:Expected expression.
我已经看过Apple的格式说明符,但无法弄明白.
有人可以向我解释如何做到这一点?
谢谢!
我有两个窗口应用程序,当我呈现第一个窗口时,我希望第二个窗口中的视图加载并准备以后在后台的内容.
我试过使用方法,loadView但Apple说你不应该直接调用这个方法.
到目前为止,我已经选择使用视图的方法userInteractionEnabled,它实际上隐式调用viewDidLoad方法.
是否有一种优雅的方法可以强制ViewControllers viewDidLoad方法在自然之前(当窗口是关键并呈现时)进行激活?
我使用这行代码将本地html文件加载到Web视图中:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"html"]];
Run Code Online (Sandbox Code Playgroud)
但是我想在网址上添加一些http参数到目前为止没有运气.
我试过这个:
url = [url URLByAppendingPathComponent:@"?param1=1"];
Run Code Online (Sandbox Code Playgroud)
但在此之后,html不会加载到webview中.
有没有办法在paraview中加载webview中的本地html文件?
我有splitViewController,它具有MasterViewController的一些viewController和DetailViewController的一些tableViewController.当我按下masterViewController上的一个按钮时,我想在detailViewController中显示新的tableViewController而不是现有的.
所以我喜欢这样:
SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *searchDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:searchDetailViewController];
Run Code Online (Sandbox Code Playgroud)
之后,我将数据传递给new tableController中显示:
[searchDetailViewController passInSearchResults:listOfItems];
Run Code Online (Sandbox Code Playgroud)
之后我将"新控制器""推送"到splitViewController:
[searchSplitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, searchDetailNavigationController, nil]];
Run Code Online (Sandbox Code Playgroud)
在目标tableViewController方法中传递"passInSearchResults"数据,我也调用reloadData.方法看起来像这样:
- (void)passInSearchResults:(NSMutableDictionary *)searchResults {
self.searchResultList = searchResults;
NSLog(@"Data is passed in: %@",self.searchResultList);
[self.tableView reloadData];
//[self.tableView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
控制台:传入数据:[这里我得到了我想要的确切数据,看起来恰到好处].
After this I see that method "numberOfRowsInSection" is fired:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Setting table length: %i",[self.searchResultList count]);
return [self.searchResultList count];
}
Run Code Online (Sandbox Code Playgroud)
控制台:设置表长度:[这里我得到适当的长度]
问题是表没有填充传递的数据,并且没有调用方法"cellForRowAtIndexPath".
怎么可能在reloadData方法"numberOfRowsInSection"被触发但不是方法"cellForRowAtIndexPath"...... ???
谢谢
我正在使用ALAsset来检索这样的图像:
[[asset defaultRepresentation] fullResolutionImage]]
Run Code Online (Sandbox Code Playgroud)
这返回CGImageRef,我想尽快保存到磁盘...
解决方案1:
UIImage *currentImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
NSData *currentImageData = UIImagePNGRepresentation(currentImage);
[currentImageData writeToFile:filePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)
解决方案2:
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:filePath];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, [[asset defaultRepresentation] fullResolutionImage], nil);
CGImageDestinationFinalize(destination);
Run Code Online (Sandbox Code Playgroud)
问题是两种方法在设备上的执行速度都很慢.每张图像大约需要2秒才能执行此操作.这绝对是长久的.
问题:如何加快图像保存过程?或许还有更好的解决方案吗?
更新:
两种解决方案中性能的最佳改进是将图像保存为JPEG格式而不是PNG.所以对于解决方案1已经取代UIImagePNGRepresentation了UIImageJPEGRepresentation.对于解决方案2已经取代kUTTypePNG了kUTTypeJPEG.
另外值得注意的是,第二种解决方案比第一种解决方案更有效.
我有一个有趣的问题.我有一个UIScrollView,里面只有一个带图像的UIImageView.我需要这个用于缩放和平移.好.在一个按钮触摸我想要替换UIImageView中的图像(在UIScrollView中,如上所述)与下一个在线.
到目前为止,我这样做了:
self.imageView = nil;
self.imageView = [[UIImageView alloc] initWithImage:nextImage];
Run Code Online (Sandbox Code Playgroud)
我总是设置self.imageView为nil 的原因是,如果我不这样做,那么下一个图像将像前一个图像一样缩放或缩放.
但我认为这不是内存效率的精细解决方案.
是否还有其他方法可以在UIImageView上设置新图像,并使用"重置"选项进行缩放,缩放等...?
更新: 仍然不起作用的代码:
[self.scrollView setZoomScale:1.0];
[self.imageView setImage:photoImage];
[self.imageView setFrame:rect];
[self.scrollView setContentSize:[self.imageView frame].size];
CGFloat minZoomScale = [self.scrollView frame].size.width / [self.imageView frame].size.width;
if (minZoomScale < [self.scrollView frame].size.height / [self.imageView frame].size.height) {
minZoomScale = [self.scrollView frame].size.height / [self.imageView frame].size.height;
}
[self.scrollView setMinimumZoomScale:minZoomScale];
[self.scrollView setZoomScale:[self.scrollView minimumZoomScale]];
Run Code Online (Sandbox Code Playgroud)
更新2 只是弄清楚我做错了什么.我没有重置最小缩放比例.
[self.scrollView setMinimumZoomScale:1.0];
Run Code Online (Sandbox Code Playgroud)
现在它有效!
我有TableCellViewController来管理我的UITableView中的单元格.每个单元格都有一个标签na UISwitch(dictTypeSwitch).想要分配方法来切换事件,这样我就可以保存按钮的状态.
到目前为止我已经这样做了:
将setState函数赋给object:
[cell.dictTypeSwitch addTarget:self action:@selector(setState:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
处理事件的功能:
- (void)setState:(id)sender {
BOOL state = [sender isOn];
NSString *rez = state == YES ? @"YES" : @"NO";
NSLog(rez);
}
Run Code Online (Sandbox Code Playgroud)
从发件人我得到UISwitch对象,我可以从中获得状态.
到目前为止一切都很好.
但是如果我想保存UISwitch的状态,我必须得到这个单元格的rowIndex.我怎样才能做到这一点?
The cells are made inside function cellForRowAtIndexPath. Se the code bellow:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"DictionariesTableCellViewController";
DictionariesTableCellViewController *cell = (DictionariesTableCellViewController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] …Run Code Online (Sandbox Code Playgroud) 如果我想找回EKEvent从EKEventStore与eventWithIdentifier方法先前保存的事件,但我总是空.
这是添加事件的代码:
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *newEvent = [EKEvent eventWithEventStore:eventStore];
newEvent.title = @"Test";
newEvent.availability = EKEventAvailabilityFree;
newEvent.startDate = startDate;
newEvent.endDate = endDate;
[newEvent addAlarm:[EKAlarm alarmWithRelativeOffset:-15*60]];
newEvent.calendar = [eventStore defaultCalendarForNewEvents];
NSError *err;
BOOL success = [eventStore saveEvent:newEvent span:EKSpanThisEvent commit:YES error:&err];
if (success) {
if ([newEvent respondsToSelector:@selector(calendarItemIdentifier)]) {
[[NSUserDefaults standardUserDefaults] setObject:newEvent.calendarItemIdentifier forKey:self.showId];
NSLog(@"Event ID: %@",newEvent.calendarItemIdentifier);
}
else {
[[NSUserDefaults standardUserDefaults] setObject:newEvent.UUID forKey:self.showId];
NSLog(@"Event ID: %@",newEvent.UUID);
}
}
Run Code Online (Sandbox Code Playgroud)
以及删除事件的代码:
EKEventStore *eventStore = [[EKEventStore alloc] …Run Code Online (Sandbox Code Playgroud) ios ×8
iphone ×5
uitableview ×2
action ×1
add ×1
alasset ×1
append ×1
calendar ×1
constants ×1
core-data ×1
disk ×1
ekevent ×1
events ×1
image ×1
loadview ×1
logging ×1
nslog ×1
nsurl ×1
objective-c ×1
parameters ×1
reloaddata ×1
replace ×1
save ×1
selector ×1
sql ×1
string ×1
uiimage ×1
uiimageview ×1
uiscrollview ×1
uisearchbar ×1
uiswitch ×1
viewdidload ×1