我试图从Effective Java跟随Joshua Bloch的类型安全异构容器模式来创建一个对象容器(MyGeneric<T>)Class<T>作为键.
public class MyClass {
private Map<Class<?>, MyGeneric<?>> myContainer =
new HashMap<Class<?>, MyGeneric<?>>();
public <T> void addToContainer(Class<T> class, MyGeneric<T> thing) {
myContainer.put(class, thing);
}
public <T> MyGeneric<T> getFromContainer(Class<T> class) {
return (MyGeneric<T>)(myContainer.get(klass));
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于getFromContainer我必须执行未经检查的强制转换.在Josh Bloch的容器中,他表演了一个安全演员 - 但就我而言,我看不出这是怎么回事.
有没有人有任何想法?
干杯,尼克.
我想做类似于UIAlertView的事情,即 - 没有引用任何UIView或UIViewController,使用presentModalViewController在所有窗口之上呈现UIViewController.
看看文档,我找不到可行的方法!
在OS4中,有这样的东西:
UIWindow *window = [UIApplication sharedApplication].keyWindow
UIViewController *rootViewController = window.rootViewController
Run Code Online (Sandbox Code Playgroud)
......但这在OS3中是不可能的.
有谁知道如何在OS3中实现相同的效果?
谢谢!
好的 - 所以我用ViewAtroller本身的无数委托回调解决了这个问题!尽管这是实现这一目标的正确方法,但在执行的任何阶段都不可能获得警报(等)的顶级视图控制器的处理,这似乎有点奇怪.
如果有人知道如何实现这一点,我仍然会感兴趣!
当我开始开发iPhone时,我在某处读到可以将一个键值对附加到UIView.我知道所有UIViews都可以用作字典来存储你可能想要附加到它们的任何数据,以防止不必要的子类化.但是,我到处搜索找到了参考资料,并试图自己实现这种行为是徒劳的.
我尝试过这样的事情:
UIView *myView = [[UIView alloc] init];
[myView setValue:@"hello" forKey:@"world"];
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我认为上面的代码所做的是尝试将值@"hello"分配给属性@"world" - 这不是我想要的.
我正在努力实现的目标是什么?
这里的任何帮助将不胜感激.
谢谢!
缺口.
我在同一个UITableView中插入和删除UITableViewCells时遇到了很多麻烦!
我通常不发布代码,但我认为这是显示我遇到问题的最佳方式:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (iSelectedSection == section) return 5;
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"drawing row:%d section:%d", [indexPath row], [indexPath section]);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if (iSelectedSection == [indexPath section]) {
cell.textColor = [UIColor redColor];
} else {
cell.textColor = [UIColor blackColor];
}
cell.text = …Run Code Online (Sandbox Code Playgroud) 我想在键盘使用时更改键盘的UITextInputTraits ....
我理想的代码看起来像这样:
- (IBAction)nameTextDidChange:(UITextField *)sender {
if ([sender.text isEqualToString:@""]) {
sender.returnKeyType = UIReturnKeyDone;
} else {
sender.returnKeyType = UIReturnKeySearch;
}
}
Run Code Online (Sandbox Code Playgroud)
所以...我有一个不同的"返回"按钮用于空字符串,因为我做了一个带有一些文本的字符串.我上面发布的代码不起作用,键盘保留了它的原始文本输入特性.
任何人的想法,或者这是否永远不会工作无论我怎么努力?
干杯!
缺口.
感谢Deepak,这是我实际使用的代码:
if ([sender.text isEqualToString:@""]) {
sender.returnKeyType = UIReturnKeyDone;
[sender resignFirstResponder];
[sender becomeFirstResponder];
} else if (sender.returnKeyType == UIReturnKeyDone) {
NSString *cachedLetter = sender.text;
sender.returnKeyType = UIReturnKeySearch;
[sender resignFirstResponder];
[sender becomeFirstResponder];
sender.text = cachedLetter;
}
Run Code Online (Sandbox Code Playgroud) 有没有人有使用PhoneGap在所有移动平台上以JavaScript存储数据的经验?我理想的解决方案是使用像SQLite这样的东西,但遗憾的是,PhoneGap支持的所有平台都不支持SQLite.
我不久前试着提出这个问题,但它有很多不好的评分.如果您认为这是一个糟糕/毫无意义的问题,我很乐意知道,因为它有望帮助我理解这个问题!
干杯,尼克.
我有一个数据库,其中一个字段给出了空间坐标。我了解到该字段是序列化的 MSDN 几何数据类型 ( http://msdn.microsoft.com/en-us/library/bb933973.aspx )。
我想从 Python 访问这个数据库,如果有人知道几何数据类型的格式,或者任何能够在 Python 中将其解析为一组地理坐标的库,我就在徘徊。
该链接指出,Microsoft 在设计此数据类型时使用了“开放地理空间联盟 (OGC) 标准”,这是否意味着该标准定义了空间坐标?
有没有其他人有这方面的经验?
任何帮助将非常感激!
我有两个Mutable Arrays,firstArray和secondArray.两者都填充了对象.我想在firstArray中的特定点(不是在结尾而不是在开头)将secondArray中的对象添加到firstArray.有没有办法做到这一点?目前我只使用这行代码:
[self.firstArray addObjectsFromArray:secondArray];
Run Code Online (Sandbox Code Playgroud)
我想要的是FOO CODE:self.firstArray addObjectFromArray AT SPECIFIC POINT X:secondArray,specificpointX)
任何帮助表示赞赏!
我可以启动谷歌地图,邮件,Safari和其他......但是日历有相同的功能吗?
编辑:我只想在日历中添加一个事件.
多谢你们!
缺口.
我听说很多人都在谈论一种名为Memory Monitor的工具,作为检查iPhone应用程序内存使用情况的更好方法,因为Object Alloc无法准确了解应用程序实际使用的内存量.
如何启动Memory Monitor?我在仪器中找不到它.它是我必须下载的单独工具的一部分吗?
谢谢!缺口.
iphone ×4
cocoa-touch ×3
objective-c ×2
calendar ×1
cordova ×1
database ×1
dictionary ×1
generics ×1
geometry ×1
gis ×1
insert ×1
java ×1
javascript ×1
keyboard ×1
memory ×1
monitor ×1
msdn ×1
parsing ×1
python ×1
shortcut ×1
textinput ×1
uialertview ×1