我对swift很新。
谁被挤入应用程序以删除照片和要删除的评论。
我收到的消息是:
self.comments.remove(发布[" message"] as!String) self.imageFile.remove(post [" imageFile"] as!PFFile)
缺少参数标签' at:'在电话中
删除功能:
public class MainActivity extends
AppCompatActivity implements
AdapterView.OnItemSelectedListener{
Spinner spinner ;
Spinner spinner1 ;
Spinner spinner2 ;
Spinner spinner3 ;
TextView textView;
Button btn;
Time st;
Kind sk;
Hardship sh;
Lang sl;
String text;
String spin1 = st.getText().toString();
String spin2 = sk.getText().toString();
String spin3 = sh.getText().toString();
String spin4 = sl.getText().toString();
int num1 = Integer.parseInt(spin1);
int num2 = Integer.parseInt(spin2);
int num3 = Integer.parseInt(spin3);
int num4 = Integer.parseInt(spin4);
int res = 37*num1*num2*num3*num4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner = findViewById(R.id.spinner);
spinner1 = findViewById(R.id.spinner1);
spinner2 = findViewById(R.id.spinner2);
spinner3 = findViewById(R.id.spinner3);
textView = findViewById(R.id.result);
btn = findViewById(R.id.btnresult);
ArrayAdapter<Time> spinnerArrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, new Time[] {
new Time( 1, "عادی" ),
new Time( 1.5, "نیمه فوری" ),
new Time( 2, "فوری" )
});
spinner.setAdapter(spinnerArrayAdapter);
ArrayAdapter<Kind> spinner1ArrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, new Kind[] {
new Kind( 1, "مهندسی" ),
new Kind( 2, "علوم اسلامی" ),
new Kind( 1.5, "فلسفه" ),
new Kind( 1.5, "حقوق و اسناد تجاری" ),
new Kind( 1.25, "پزشکی" ),
new Kind( 1, "سایر رشته ها" )
});
spinner1.setAdapter(spinner1ArrayAdapter);
ArrayAdapter<Hardship> spinner2ArrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, new Hardship[] {
new Hardship( 1, "عمومی" ),
new Hardship( 1.2, "تخصصی" )
});
spinner2.setAdapter(spinner2ArrayAdapter);
ArrayAdapter<Lang> spinner3ArrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, new Lang[] {
new Lang( 1.5, "عربی" ),
new Lang( 1.5, "فرانسه" ),
new Lang( 1.5, "آلمانی" ),
new Lang( 1.5, "ترکی استانبولی" ),
new Lang( 1.5, "ترکی آذری" ),
new Lang( 1.5, "روسی" ),
new Lang( 1.5, "ارمنی" ),
new Lang( 1.75, "اسپانیایی" ),
new Lang( 1.75, "ایتالیایی" ),
new Lang( 1.75, "کردی" ),
new Lang( 2, "چینی" ),
new Lang( 2, "کره ای" ),
new Lang( 2, "ژاپنی" ),
new Lang( 2, "اردو" ),
new Lang( 2, "مجاری" ),
new Lang( 2, "سوئدی" ),
new Lang( 2, "هلندی" ),
new Lang( 2, "تاجیک" ),
new Lang( 2, "لهستانی" )
});
spinner3.setAdapter(spinner3ArrayAdapter);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
st = (Time)spinner.getSelectedItem();
sk = (Kind)spinner1.getSelectedItem();
sh = (Hardship)spinner2.getSelectedItem();
sl = (Lang)spinner3.getSelectedItem();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText(res);
}
});
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public class Time {
public double id ;
public String name ;
public Time( double _id, String _name )
{
id = _id;
name = _name;
}
public String toString()
{
return name;
}
}
public class Kind {
public double id ;
public String name ;
public Kind( double _id, String _name )
{
id = _id;
name = _name;
}
public String toString()
{
return name;
}
}
public class Hardship {
public double id ;
public String name ;
public Hardship( double _id, String _name )
{
id = _id;
name = _name;
}
public String toString()
{
return name;
}
}
public class Lang {
public double id ;
public String name ;
public Lang( double _id, String _name )
{
id = _id;
name = _name;
}
public String toString()
{
return name;
}
}
}
有人可以告诉我我做错了什么以及我该如何做对吗?
感谢您的帮助
答案 0 :(得分:1)
数组上没有remove
方法将您要删除的内容作为参数删除,您只能删除某个索引处的元素:
self.comments.remove(at: self.comments.index(of: post["message"] as! String)!)
如果您需要这样的remove
功能,请考虑使用Set
代替,或编写自己的分机:
extension Array where Element : Equatable {
@discardableResult
mutating func remove(element: Element) -> Element? {
guard let i = self.index(of: element) else { return nil }
return self.remove(at: i)
}
}
答案 1 :(得分:0)
查看remove(at:)
函数here的签名:
@discardableResult mutating func remove(at index: Int) -> Array.Element
您只需添加&#39; at:&#39;在你的电话中如下:
self.comments.remove(at: /*Have an Int here*/)
self.imageFile.remove(at: /*Have an Int here*/)
确保comments和imageFile是remove(at:)
可变数组才能工作。