我有一个UISearchBar在titleView导航栏(它看起来像下面的图片)的,我想使它的工作方式类似于一个在Safari浏览器.
我没有足够的声誉来发布图片,这是链接
第一张照片

第二张照片

我想要实现的目标是:
UISearchBar在该搜索栏内有一个清除按钮(看起来像带有2个加法按钮的第一张图片).view被另一个取代view,当它被解雇时,view返回到原始状态.我知道这可以通过使用来完成,UISearchDisplayController但它不起作用.这是我的代码:
.h:实施TableView's DataSource/Delegate, UISearchDisplayDelegate, UISearchBarDelegate
.M
-(void) viewDidload
{
//Add left, right buttons
self.leftButton = [[UIBarButtonItem alloc] init];
[self.leftButton setStyle:UIBarButtonItemStylePlain];
[self.leftButton setTitle:@"Button"];
self.navigationItem.leftBarButtonItem = self.leftButton;
self.rightButton = [[UIBarButtonItem alloc] init];
[self.rightButton setStyle:UIBarButtonItemStylePlain];
[self.rightButton setTitle:@"Button"];
self.navigationItem.rightBarButtonItem = self.rightButton;
self.searchBar = [[UISearchBar alloc] initWithFrame:self.navigationController.navigationBar.bounds];
if (DEVICE_IS_IOS7) {
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
}
self.navigationItem.titleView = self.searchBar;
self.searchBar.delegate = self; …Run Code Online (Sandbox Code Playgroud) 我有一个UIButton透明背景和白色标题的自定义.我正在寻找一个简单的解决方案,以便在系统上实现高亮(白色背景和透明标题)时将其反转UISegmentedControl.
有没有比在用作CALayer掩码的快照上反转alpha更简单的解决方案?
如果没有,你能告诉我怎样才能反转CALayeralpha?
我正在使用UINavigationController它的默认值UINavigationBar,我试图关闭半透明效果,所以我可以在它上面有一个纯色.显然,它不适用于代码,但只需单击一下就可以使用故事板(很奇怪?!!)
我的代码:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:APP_DELEGATE.map];
[navController setToolbarHidden:YES];
[navController.navigationBar setTranslucent:NO];
[navController.navigationBar setBarTintColor:[UIColor turquoiseColor]];
// [[UINavigationBar appearance] setBarTintColor:[UIColor turquoiseColor]]; | also doesn't work
Run Code Online (Sandbox Code Playgroud)
为什么不起作用?我该如何解决这个问题?谢谢.
objective-c uinavigationbar uinavigationcontroller ios uistoryboard
我正在使用Xcode 5.1.1运行最新的Mavenricks
我从苹果公司下载了Xcode 6 beta版,这条消息不断出现.因此,我几乎不能编写任何代码,因为禁用了代码完成.
有谁知道如何解决这一问题 ?

我在Objective-C中对这些方法进行了研究.它们只是校验和而XORNSData
- (void)XOR:(NSMutableData *)inputData withKey:(NSData *)key
{
unsigned char* inputByteData = (unsigned char*)[inputData mutableBytes];
unsigned char* keyByteData = (unsigned char*)[key bytes];
for (int i = 0; i < [inputData length]; i++)
{
inputByteData[i] = inputByteData[i] ^ keyByteData[i % [key length]];
}
}
- (Byte)checkSum:(NSMutableData *)data withLength:(Byte)dataLength
{
Byte * dataByte = (Byte *)malloc(dataLength);
memcpy(dataByte, [data bytes], dataLength);
Byte result = 0;
int count = 0;
while (dataLength>0) {
result += dataByte[count];
dataLength--;
count++;
};
result = result&0xff;
return result&0xff; …Run Code Online (Sandbox Code Playgroud) 我有这个自定义的实现Alamofire:
protocol HTTPProtocol: class {
typealias RequestType
typealias RespondType
func doRequest(requestData: RequestType) -> Self
func completionHandler(block:(Result<RespondType, NSError>) -> Void) -> Self
}
//example of a request:
locationInfo
//Make a request
.doRequest(HTTPLocationInfo.RequestType(coordinate: $0))
//Call back when request finished
.completionHandler { result in
switch result {
case .Success(let info): self.locationInfoRequestSuccess(info)
case .Failure(let error): self.locationInfoRequestFailed(error)
}
}
Run Code Online (Sandbox Code Playgroud)
我想将MVVM和RxSwift应用到我的项目中.但是,我找不到合适的方法来做到这一点.
我想要实现的是a ViewModel和a ViewController可以做这些事情:
class ViewController {
func googleMapDelegate(mapMoveToCoordinate: CLLocationCoordinate2D) {
// Step 1: set new value on `viewModel.newCoordinate` and make a …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifierNormal = @"CellNormal";
static NSString *CellIdentifierTracking = @"CellTracking";
switch (self.mapState) {
case MapStateNormal:
{
// UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:CellIdentifierNormal];
// if (cell == nil) {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierNormal];
// }
[cell.textLabel setText:@"abc"];
return cell;
}
case MapStateTracking:
{
// UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:CellIdentifierTracking];
// if (cell == nil) {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierTracking];
// }
if (indexPath.row == 0) {
[cell.textLabel setText:@"Lorem ipsum"]; …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
- (UITableView *)table {
if (!_table) {
_table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
[_table setDelegate:self];
[_table setDataSource:self];
[_table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
return _table;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
else
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我registerClass为我的桌子时,它假定我的细胞样式是UITableViewCellStyleDefault.所以这就是为什么detailTextLabel不出现.我测试了它.
注释掉该registerClass行不起作用,因为我没有任何CellIdentifier用途dequeueReusableCell.所以它会抛出一些例外.
如果我不使用dequeue,它可以工作,但这不是最好的做法.
AFAIK,表格单元格在初始化后无法改变其样式.那我该如何制作detailTextLabel秀呢?
好吧,这可能是一个重复的问题.
我发现了一些像这样的问题:
有没有办法在Swift中设置相关对象?
但是,我想在Intswift中添加一个属性extension,上面链接中的这些答案不起作用.
这是我的代码:
import ObjectiveC
var xoAssociationKey: UInt8 = 0
extension NSData {
var position: Int {
get {
return objc_getAssociatedObject(self, &xoAssociationKey) as Int
}
set {
objc_setAssociatedObject(self, &xoAssociationKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}
}
override convenience init() {
self.init()
position = 0
}
}
Run Code Online (Sandbox Code Playgroud)
我fatal error: unexpectedly found nil while unwrapping an Optional value每次访问都会得到position
仅供参考,我确实在Objective C中找到了这个错误的解决方案,我正在寻找一个快速的解决方案.如果您感兴趣,这是我在目标C中的代码:
static char PROPERTY_KEY;
@implementation NSData (Extension)
@dynamic position;
- (NSInteger)position {
return [objc_getAssociatedObject(self, &PROPERTY_KEY) …Run Code Online (Sandbox Code Playgroud) 嗯,说实话,我不喜欢rawValue在访问enum价值时打电话.
我enum几乎一直都这样使用,我认为调用.rawValue使我的代码不那么"可读":
enum FontSize: CGFloat {
case Small = 12
case Normal = 15
case Large = 18
}
enum Example: String {
case First = "First"
case Second = "Second"
}
Run Code Online (Sandbox Code Playgroud)
所以,我正在尝试为enum"覆盖" 定义一个泛型运算符.rawValue.
我可以非一般地做.
postfix operator .. { }
postfix func .. (lhs: Example) -> String {
return lhs.rawValue
}
postfix func .. (lhs: FontSize) -> CGFloat {
return lhs.rawValue
}
Run Code Online (Sandbox Code Playgroud)
但是,我很懒,我想要一个通用的解决方案.写一个,全部工作.
有人可以帮我吗?谢谢.
更新:如果您希望增加/减少功能谁感兴趣这个问题,人们enum喜欢 …
我正在开发一个没有ARC的旧项目.它有很多错误,代码看起来很难看,我正在重写它.
快速浏览一下我的代码吧
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell = [self createCellWithInfo:[self.search objectAtIndex:indexPath.row]];
return cell;
}
-(UITableViewCell *)createCellWithInfo:(NSDictionary *)info{
UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@“Cell”] autorelease];
//set image for cell
//set text for cell.textlabel
//set text for cell.detailTextLabel
//create an UIButton and add to cell.content view
return cell;
}
Run Code Online (Sandbox Code Playgroud)
重点在于这行代码
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@“Cell”] autorelease]
如果我@"Cell" …
ios ×10
objective-c ×6
swift ×5
uitableview ×3
alpha ×1
calayer ×1
mvvm ×1
nsdata ×1
rx-swift ×1
uibutton ×1
uistoryboard ×1
xcode6 ×1